Re: default value based on select - Mailing list pgsql-general

From Volkan YAZICI
Subject Re: default value based on select
Date
Msg-id 87prt4bo06.fsf@alamut.mobiliz.com.tr
Whole thread Raw
In response to default value based on select  (Pedro Doria Meunier <pdoria@netmadeira.com>)
List pgsql-general
On Sat, 5 Apr 2008, Pedro Doria Meunier <pdoria@netmadeira.com> writes:
> Is it possible to have a table's column default value set to some form of
> select?

AFAIK, you cannot provide sub-selects in the default values of a
field. E.g.

  CREATE TABLE foo (bar int DEFAULTS (SELECT ...), ...);

For this, I know two solutions:

1. You can create an SQL function that issues the related sub-select and
   call this function as the default value of the column.

2. Create a BEFORE INSERT/UPDATE trigger that issues the related
   sub-select if related column appears to be un-specified.


Regards.

pgsql-general by date:

Previous
From: "Pavel Stehule"
Date:
Subject: Re: default value based on select
Next
From: Pedro Doria Meunier
Date:
Subject: Re: default value based on select