Re: cannot use column references in default expression?

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: cannot use column references in default expression?
Date: 2010-05-28 17:47:59
Message-ID: 9ECED4D8-B1B4-43F9-A848-1E3DD74A8160@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On May 28, 2010, at 10:41 AM, Jignesh Shah wrote:

> Trigger should be the last solution. This used to be working but I
> think with latest postgresql upgrade, this stopped working. Might be
> someone around here knows whats going on here.

I'm afraid not. It's never been allowed to have a variable in the
expression for a DEFAULT value. To quote the manual:

> 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.
>
A trigger is the appropriate solution in this case.

--
-- Christophe Pettus
xof(at)thebuild(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2010-05-28 17:50:35 Re: cannot use column references in default expression?
Previous Message Jignesh Shah 2010-05-28 17:41:02 Re: cannot use column references in default expression?