Re: Is there any easy way to determine a default value specified for table column?

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Is there any easy way to determine a default value specified for table column?
Date: 2010-03-14 18:52:21
Message-ID: hnjb8s$obs$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Belka Lambda wrote on 14.03.2010 01:24:
> Hi everyone!
>
> Is there a way to "nicely" determine a default value of a table column? A function, which could be used, like:

The defaults are store in pg_attrdef, the corresponding column definitions in pg_attribute.

So you would need to do a join between the two tables, something like:

select c.relname, a.attname, def.adsrc
from pg_attrdef def
join pg_class c on def.adrelid = c.oid
join pg_attribute a on a.attrelid = c.oid and a.attnum = def.adnum
where c.relname = 'the_table_name'

Thomas

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-03-14 19:23:36 Re: Re: Is there any easy way to determine a default value specified for table column?
Previous Message Adrian Klaver 2010-03-14 18:15:09 Re: OIDs depending data -- how to dump/restore?