Jean-Christophe Roux wrote:
Hello,
How can I get the default value for a column?
To change the default value, something like
ALTER TABLE dummy ALTER COLUMN value SET DEFAULT -12;
would do the job, but how could I query the value?
Thanks in advance
You can select from the pg_ system tables, but there is now an easier
method with PostgreSQL 7.4+.
What you want is the (redundantly-named) "information_schema" schema in
any PostgreSQL database. I take it you have installed phpPgAdmin
(phppgadmin.sf.net)? Then just open it and navigate to
information_schema inside your database, and look for the View titled
'columns', and a column titled 'column_default'. So your query would
look something like:
SELECT column_default FROM information_schema.columns WHERE
table_name='your_table_name';
or if needed:
SELECT column_default FROM information_schema.columns WHERE
table_name='your_table_name' AND schema='whatever_schema';
(this would be needed if you have a duplicate table name in more than
one schema)
HTH,
Regards,
Rick Morris