Question

retrieve last used oid value and set counter to start with next number. Postgres 14/PostGIS oid

  • 31 July 2023
  • 1 reply
  • 9 views

Badge +10

I am writing to postgres/postgis st_geometry in an autmation that is loading many dwg datasets. (runs workbench on each dwg)

The postgis writer shows that ver 14 ignores writing od. 

I need to get an oid calculated beginning with the last oid used (in the previous automation)

NOTE: postgis writer specifies that oid is ignored at postgres 14.

I tried just using a counter and hoped that writing to existing would automatically write the oid. (I get an error the oid already exists).

I am using this oid as the primary key so that It doesn't have to be set when adding to esri.

I have attempted to read the flat postgres table and sample the last n and then use that as a parameter to set the start number of the counter. But have not been successful getting that to work.

imageAny ideas on how to do this?

 


1 reply

Userlevel 5
Badge +28

well, if your oid's are always sequential (that is the highest number is the most recent) then you can use this call inside an SQLExcecutor to get the last row.

SELECT * FROM "<table_name>" 
ORDER BY "oid" DESC
LIMIT 1;

This should give you the last record from the table. From there you can use a counter starting from the oid value (or oid+1 ).

Reply