databasepostgresqlpostgresql-9.1objectidzend-db-table

How to get the OID of a Postgres table?


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.


Solution

  • The postgres catalog table pg_class is what you should look at. There should be one row per table, with the table name in the column relname, and the oid in the hidden column oid.

    You may also be interested in the pg_attribute catalog 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