Adding PrimaryKey (PostgreSQL PostGIS database) - Best Practices
Hello all,
I would like to create a simple FME workspace in which PostGIS writer automatically reads attributes from the reader and adds an attribute with PrimaryKey (there are 30+ feature types in total). Is it possible to do it somehow?
However, the goal is to set up a straightforward process with automatic attribute definition.
I would really appreciate it if you could share what methods you use.
Page 1 / 1
I’ve attached an example workspace built in 2024.1. It’s built as a dynamic workspace so you should be able to substitute the database connection with your own, then run it. It will add a new field called ‘guid’ to every table the connect has access to.
Please don’t run it blindly. Have a look at it first and understand what it does before trying on a local/dev env where data loss will not be an issue.
It is a bit of a ‘sledgehammer’ approach where it drops the existing table and recreates it with a new field.
A safer, yet slightly more complex approach would be to make use of the ALTER TABLE function in PostgreSQL and get the database to populate the guids. This doesn’t drop and recreate tables, but is a database level action rather than an FME one. That being said you could run it from an SQLExecutor. An example of that is something along the lines of: https://chatgpt.com/share/67900e19-c224-8005-a8d9-dae8ddc2dcc0