Re: Column Default Clause and User Defined Functions - Mailing list pgsql-general

From Tom Lane
Subject Re: Column Default Clause and User Defined Functions
Date
Msg-id 20676.1183006919@sss.pgh.pa.us
Whole thread Raw
In response to Re: Column Default Clause and User Defined Functions  (Michael Glaesemann <grzm@seespotcode.net>)
Responses Re: Column Default Clause and User Defined Functions  (Michael Glaesemann <grzm@seespotcode.net>)
List pgsql-general
Michael Glaesemann <grzm@seespotcode.net> writes:
> On Jun 27, 2007, at 18:18 , Keary Suska wrote:
>> Is it possible to have a user-defined function (a plpqsql function)
>> as the
>> argument to a default clause that issues SELECTs on other tables?

> Not according to the documentation:
> http://www.postgresql.org/docs/8.2/interactive/sql-createtable.html

What those docs say is that you can't have a naked sub-SELECT in the
DEFAULT expression.  This is to some extent an implementation limitation
--- we don't do planning on DEFAULT expressions.  You can definitely get
around it by hiding the sub-SELECT in a function.

Whether that is a good idea is another question entirely ... it seems
a bit questionable, but on the other hand time-varying defaults like
"default now()" have time-honored usefulness, so I'm not quite sure
why I feel uncomfortable with it.

            regards, tom lane

pgsql-general by date:

Previous
From: "Luki Rustianto"
Date:
Subject: Pg7.4.x plpgsql trigger execution order bug
Next
From: Tom Lane
Date:
Subject: Re: Pg7.4.x plpgsql trigger execution order bug