Does anyone know how to find the OID of a table in Postgres 9.1?
I am writing an update script that needs to test for the existence of a column in a table before it tries to add the column. This is to prevent errors when running the script repeatedly.
The postgres catalog table
pg_classis what you should look at. There should be one row per table, with the table name in the columnrelname, and the oid in the hidden columnoid.You may also be interested in the
pg_attributecatalog table, which includes one row per table column.See: http://www.postgresql.org/docs/current/static/catalog-pg-class.html and http://www.postgresql.org/docs/current/static/catalog-pg-attribute.html