Re: Column Default Clause and User Defined Functions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: Keary Suska <hierophant(at)pcisys(dot)net>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Column Default Clause and User Defined Functions
Date: 2007-06-28 05:01:59
Message-ID: 20676.1183006919@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michael Glaesemann <grzm(at)seespotcode(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-06-28 05:26:05 Re: Pg7.4.x plpgsql trigger execution order bug
Previous Message Luki Rustianto 2007-06-28 04:51:02 Pg7.4.x plpgsql trigger execution order bug