Re: get column default value

From: Erik Jones <erik(at)myemma(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 19:16:24
Message-ID: 4558C488.8090804@myemma.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

If you want to use variables in your queries with procedural functions
you need to build the query as a string and use EXECUTE to run it like so:

EXECUTE 'alter table accounts_post_history_payout alter column
payout_rate set default ' || payout_rate_in || ';';

Jean-Christophe Roux wrote:
> Hi,
> Thank you very much for the tip; it works fine and I can query easily
> default values.
> I have this function:
> CREATE OR REPLACE FUNCTION
> func_accounts_post_history_default(payout_rate_in numeric)
> RETURNS text AS
> $BODY$
> declare
> i integer;
> begin
> --alter table accounts_post_history_payout alter column
> payout_rate set default payout_rate_in;
> alter table accounts_post_history_payout alter column payout_rate
> set default 0;
> return 'Default values have been updated.';
> end;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
>
> The uncommented alter command works but the commented one does not
> work because it apparently lacks the new default value. Any idea how
> I should change the syntax? I find it strange because I usually do not
> have any problem using parameters in my function.
>
> Thanks
>
>
>
> ----- Original Message ----
> From: Erik Jones <erik(at)myemma(dot)com>
>
> >> 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(at)myemma(dot)com>
> software development
> emma(r)
>
>
>

--
erik jones <erik(at)myemma(dot)com>
software development
emma(r)

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Jean-Christophe Roux 2006-11-13 19:42:58 Re: get column default value
Previous Message Jean-Christophe Roux 2006-11-13 19:01:47 Re: get column default value