I\'m looking for a way to run a query to find the default values of the columns of a table in Postgres. For example, if I made a table with the following query:
Use the information schema:
SELECT column_name, column_default
FROM information_schema.columns
WHERE (table_schema, table_name) = ('public', 'mytable')
ORDER BY ordinal_position;
column_name │ column_default
─────────────┼────────────────────────────────────────
integer │ 2
text │ 'I am default'::character varying
moretext │ 'I am also default'::character varying
unimportant │
(4 rows)
Up to the schema naming, this should work in any SQL database system.