Feb 23
PostgreSQL: Determine if a column exists or not.
Here’s a quick query you can run to determine whether or not a particular column in a table exists or not:
SELECT attname FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = ‘YOURTABLENAME’) AND attname = ‘YOURCOLUMNNAME’;
Of course, replace YOURTABLENAME and YOURCOLUMNNAME with the proper values. If a row is returned, a column with that name exists, otherwise it does not.
