Re: defaults referencing other columns? - Mailing list pgsql-novice

From Richard Broersma Jr
Subject Re: defaults referencing other columns?
Date
Msg-id 20060904014650.14524.qmail@web31801.mail.mud.yahoo.com
Whole thread Raw
In response to defaults referencing other columns?  (James Cloos <cloos@jhcloos.com>)
Responses Re: defaults referencing other columns?
List pgsql-novice
> Can a default value reference the value specified for one of the other
> columns in the insert?

from:
http://www.postgresql.org/docs/8.1/interactive/sql-createtable.html


DEFAULT default_expr
The DEFAULT clause assigns a default data value for the column whose column definition it appears
within. The value is any variable-free expression (subqueries and cross-references to other
columns in the current table are not allowed). The data type of the default expression must match
the data type of the column.

The default expression will be used in any insert operation that does not specify a value for the
column. If there is no default for a column, then the default is null.

>                    bar TEXT DEFAULT somefunc(id)

"The value is any variable-free expression".  To me the "id" in somefunc would classify as a
variable.  The other suggestion to use a Rule might work,  however a before insert trigger would
diffently work in this case.

However, why would you what to to store the text anyway? If you wanted to see it you could still
generate "on the fly" with a select statement.

select id, somefunc(id) from foo;

Regards,

Richard Broersma Jr.

pgsql-novice by date:

Previous
From: "Jasbinder Bali"
Date:
Subject: Re: defaults referencing other columns?
Next
From: Richard Broersma Jr
Date:
Subject: Re: function parameters