This project has moved and is read-only. For the latest updates, please go here.

[PostGIS provider] oidColumn problem

Topics: Data Access, SharpMap v2.0
Dec 19, 2008 at 2:30 PM


I am trying to evaluate PostGIS data provider. Can someone explain what is oidColumn in the constructor of PostGisProvider?

What i've understood from MapViewer demo oidColumn is the name of the primary key column. If it is so, so the name oidColumn is misleading because oid is a system

column in PostgreSQL with unique id of the row.

The question is why is it so important to provide the name of the primary key column? And what if i have more than one column as a primary key?

Also, why the data type of the primary key column should be provided as a generic parameter TOid ? I don't have any primary keys in my spatial data and it makes very difficult to use PostGIS provider.

Dec 19, 2008 at 2:52 PM
Hi slaks, you're correct the oidColumn is the name of the primary key column.  Note the oidColumn does not have to be a real primary key in the database but it does need to contain unique values across the whole table. 
The oidColumn is important because it is used in updates deletes and certain types of select etc.
At the moment only single column keys are supported.
The datatype for the generic parameter should be the .net equivalent of the column type in the database e.g Int32, Int64, Guid etc.
I am pretty sure the performance of your database would improve with the addition of primary keys hth jd
Dec 19, 2008 at 3:11 PM

Hi, johndiss

Thanks for clarification. In case when the table doesn't contain explicit primary keys would be better to use oid system table as a primary key table if  table was created "WITH (OIDS=TRUE);"

MapViewer demo throws exception "Column "oid" doesn't allow nulls" when layer is being added. I don't know if it is only a demo problem or the problem lies somewhere in postgis provider class.


Dec 19, 2008 at 3:36 PM
Edited Dec 19, 2008 at 3:37 PM
I dont know too much about the specifics of PostGis - I work mostly with sql server, but I cant see any reason why you shouldn't be able to use the oid from the system table.
The error you are seeing probably comes from a constraint in the FeatureDataTable class.
I don't know what tools exist but if there is a profiling tool for postgres it may be worth tracing the executed sql and then running it yourself to check that the oid column has values.. hth jd 
Dec 19, 2008 at 7:50 PM
Edited Dec 19, 2008 at 8:01 PM
Hi slaks,
the problem is that the SQLstatement
in the BuildTableSchema function does not return the oid column, even if the table was created with oid=true. Therefore you get an empty oid-column. Do you know how to determine whether a table was set up like that?

In the Test folder of SharpMap.Data.Providers.PostGis Project you can find a routine called
void T11_JD_Test()
where there is a query set up that uses
class along with
class. If explictly include "oid", you might be able to include the "missing" oid Column and get the query to work.
hth FObermaier