pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rick Morris <rick@brainscraps.com>
To: Jean-Christophe Roux <jcxxr@yahoo.com>
Cc: pgsql-php@postgresql.org
Subject: Re: get column default value
Date: Mon, 13 Nov 2006 12:25:28 -0500
Message-ID: <4558AA88.3070102@brainscraps.com> (raw)
In-Reply-To: <20061113144914.83394.qmail@web35307.mail.mud.yahoo.com>
References: <20061113144914.83394.qmail@web35307.mail.mud.yahoo.com>

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



view thread (9+ messages)  latest in thread

Message-ID: <4558AA88.3070102@brainscraps.com>
Permalink:  ../4558AA88.3070102@brainscraps.com/
Also on:    postgresql.org/message-id/4558AA88.3070102@brainscraps.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: rick@brainscraps.com, jcxxr@yahoo.com
  Subject: Re: get column default value
  In-Reply-To: <4558AA88.3070102@brainscraps.com>
  References: <20061113144914.83394.qmail@web35307.mail.mud.yahoo.com> <4558AA88.3070102@brainscraps.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox