Re: Can I get the default value for an attribute (field) ?

From: Joel Burton <jburton(at)scw(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Can I get the default value for an attribute (field) ?
Date: 2001-04-01 21:32:42
Message-ID: Pine.LNX.4.21.0104011729310.6059-100000@olympus.scw.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I'm building a GUI for a PostgreSQL database. In the DB, many fields have
> default values (a few are complicated, like the results of a sequence, but
> most are simple things like FALSE or 0 or such.)
>
> Is there a way to get what the default value for a field would be when a
> new record is added? For some tables, I could (behind the users back) add
> a row, grab the values given in each column, delete the row, then
> present these as 'default' values; however, in most tables, there are
> columns that cannot be null and do not have default values, therefore I
> can't just add a row using the default-only values.
>
> I've been looking around for a miraculous SELECT
> default_value(table.class) function, but can't seem to find it. Any ideas?

I should have mentioned that I know the default values are stored in
pg_attrdef, in 'human' mode at adsrc, and in 'pg' mode at adbin; I could
look there, but don't know how to 'evaluate' these to the real-world
equivalents (ie, instead of finding 'f' or FALSE in a column, I get
'f'::bool, and by the time this gets to the GUI app and back again, it
looks like '''f''::bool' to PG, so it sees it as text, not as the boolean
value false. Similarly, "current_user"() isn't resolved, etc.

So, one solution might be: is there a way to 'resolve' these before they
come to the front-end?

Thanks!

--
Joel Burton <jburton(at)scw(dot)org>
Director of Information Systems, Support Center of Washington

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Paul Tomblin 2001-04-01 21:32:46 Re: Ok, why isn't it using *this* index?
Previous Message ADBAAMD 2001-04-01 21:26:48 Re: another index question