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

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: "'Joel Burton'" <jburton(at)scw(dot)org>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: RE: Can I get the default value for an attribute (field) ?
Date: 2001-04-01 22:52:03
Message-ID: 01C0BADC.D83FB880.mascarm@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you start psql with the -E option you'll see it generates a query
similar to the following:

SELECT substring(d.adsrc for 128) FROM pg_attrdef d, pg_class c
WHERE c.relname = 'my_table' AND c.oid = d.adrelid NAD d.adnum = X

where my_table is the table in question and X is the column number
within that table.

Hope that helps,

Mike Mascari
mascarm(at)mascari(dot)com

-----Original Message-----
From: Joel Burton [SMTP:jburton(at)scw(dot)org]
Sent: Sunday, April 01, 2001 5:25 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] Can I get the default value for an attribute
(field) ?

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?

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

---------------------------(end of
broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Gaszewski 2001-04-01 22:54:03 PostgreSQL 7.1, UNICODE and glibc
Previous Message Tom Lane 2001-04-01 22:51:12 Re: How do I...