From: | Rick Morris <rick(at)brainscraps(dot)com> |
---|---|
To: | Jean-Christophe Roux <jcxxr(at)yahoo(dot)com> |
Cc: | pgsql-php(at)postgresql(dot)org |
Subject: | Re: get column default value |
Date: | 2006-11-13 17:25:28 |
Message-ID: | 4558AA88.3070102@brainscraps.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-php |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Jean-Christophe Roux | 2006-11-13 19:01:47 | Re: get column default value |
Previous Message | Ash | 2006-11-13 16:36:19 | Unsubscribe |