Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 597DD9FB20F for ; Mon, 13 Nov 2006 11:19:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 36270-03 for ; Mon, 13 Nov 2006 11:19:30 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from myemma.com (db1.e2ma.net [66.179.147.163]) by postgresql.org (Postfix) with ESMTP id 9B4E09FB1F2 for ; Mon, 13 Nov 2006 11:19:28 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by myemma.com (Postfix) with ESMTP id 0567723CE3; Mon, 13 Nov 2006 09:19:27 -0600 (CST) Received: from myemma.com ([127.0.0.1]) by localhost (velma [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 22568-08; Mon, 13 Nov 2006 09:19:26 -0600 (CST) Received: from [192.168.1.11] (c-71-228-218-92.hsd1.tn.comcast.net [71.228.218.92]) by myemma.com (Postfix) with ESMTP id 4544023CDB; Mon, 13 Nov 2006 09:19:26 -0600 (CST) Message-ID: <45588CFC.4000304@myemma.com> Date: Mon, 13 Nov 2006 09:19:24 -0600 From: Erik Jones User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: Jean-Christophe Roux Cc: Ketema Harris , pgsql-php@postgresql.org Subject: Re: get column default value References: <20061113150352.91895.qmail@web35303.mail.mud.yahoo.com> In-Reply-To: <20061113150352.91895.qmail@web35303.mail.mud.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at myemma.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/44 X-Sequence-Number: 3661 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 > To: Jean-Christophe Roux > 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 software development emma(r)