Re: get column default value - Mailing list pgsql-php

From Rick Morris
Subject Re: get column default value
Date
Msg-id 4558AA88.3070102@brainscraps.com
Whole thread Raw
In response to get column default value  (Jean-Christophe Roux <jcxxr@yahoo.com>)
List 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

pgsql-php by date:

Previous
From: Erik Jones
Date:
Subject: Re: get column default value
Next
From: "Ash"
Date:
Subject: Unsubscribe