pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Erik Jones <erik@myemma.com>
To: Jean-Christophe Roux <jcxxr@yahoo.com>
Cc: Ketema Harris <ketema@gmail.com>
Cc: pgsql-php@postgresql.org
Subject: Re: get column default value
Date: Mon, 13 Nov 2006 09:19:24 -0600
Message-ID: <45588CFC.4000304@myemma.com> (raw)
In-Reply-To: <20061113150352.91895.qmail@web35303.mail.mud.yahoo.com>
References: <20061113150352.91895.qmail@web35303.mail.mud.yahoo.com>

Jean-Christophe Roux wrote:
> I understand that but I need to build an interface so that my user can 
> change the default values of some table/columns. So I need a way to 
> query the current default value to show the user what it is currently. 
> For instance, let's say I have a table products and there is a column 
> price and the default price is $199, I'd like to get that $199 and 
> give my user the opportunity to update that value. The column does not 
> have any sequence attached to it.
> JCR
>
> ----- Original Message ----
> From: Ketema Harris <ketema@gmail.com>
> To: Jean-Christophe Roux <jcxxr@yahoo.com>
> Cc: pgsql-php@postgresql.org
> Sent: Monday, November 13, 2006 9:59:29 AM
> Subject: Re: [PHP] get column default value
>
> The default value for a column is just that the value you say is 
> default.  It only come into play when you do an insert into the 
> table.  If you do not provide a value for that column then your 
> default value is entered.
>
> Now if you set the default value of a column to a sequence, then you 
> can manage the sequence using the sequence functions: currval, 
> nextval, and setval.  Sequences and their functions are documented in 
> the pg manual.
>
> On Nov 13, 2006, at 9:49 AM, 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
>
SELECT adsrc as default_value
FROM pg_attrdef pad, pg_atttribute pat, pg_class pc
WHERE pc.relname='your_table_name'
    AND pc.oid=pat.attrelid AND pat.attname='your_column_name'
    AND pat.attrelid=pad.adrelid AND pat.attnum=pad.adnum

-- 
erik jones <erik@myemma.com>
software development
emma(r)




view thread (9+ messages)  latest in thread

Message-ID: <45588CFC.4000304@myemma.com>
Permalink:  ../45588CFC.4000304@myemma.com/
Also on:    postgresql.org/message-id/45588CFC.4000304@myemma.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: erik@myemma.com, jcxxr@yahoo.com, ketema@gmail.com
  Subject: Re: get column default value
  In-Reply-To: <45588CFC.4000304@myemma.com>
  References: <20061113150352.91895.qmail@web35303.mail.mud.yahoo.com> <45588CFC.4000304@myemma.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