| From: | Volkan YAZICI <yazicivo(at)ttmail(dot)com> |
|---|---|
| To: | Pedro Doria Meunier <pdoria(at)netmadeira(dot)com> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: default value based on select |
| Date: | 2008-04-05 10:21:45 |
| Message-ID: | 87prt4bo06.fsf@alamut.mobiliz.com.tr |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Sat, 5 Apr 2008, Pedro Doria Meunier <pdoria(at)netmadeira(dot)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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Pedro Doria Meunier | 2008-04-05 11:25:20 | Re: default value based on select |
| Previous Message | Pavel Stehule | 2008-04-05 10:14:45 | Re: default value based on select |