Re: PostgreSQL: Question about rules - Mailing list pgsql-general

From Jeff Davis
Subject Re: PostgreSQL: Question about rules
Date
Msg-id 1163730833.4514.11.camel@dogma.v10.wvs
Whole thread Raw
In response to Re: PostgreSQL: Question about rules  ("Jeremy Smith" <postgres@duckwizard.com>)
Responses Re: PostgreSQL: Question about rules  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Thu, 2006-11-16 at 16:58 -0800, Jeremy Smith wrote:

>
> One more thing that would sweeten the deal even further! Not so much
> for sequences, but for other columns with default values:
>
> insert into foo(bar) values(COALESCE(new.bar, DEFAULT))
>
> This doesn't work, because DEFAULT is a language construct that is
> only defined within the immediate scope of the values(...) list.  Is
> there any way I can use COALESCE to defer to the table for the default
> value, rather than explicitly specifying it?
>
> I could probably fake this by writing a function to look up the
> default value in pg_attrdef and evaluate it - just want to see if
> there is a built-in function for this (I can't find one).  Because it
> would be a lot of work :-)
>

Interesting question. It seems like you're trying to make a default
value for a view that's based on the underlying table's default value.

I think the normal way to do this is to _not_ have a default value on
the underlying table, and instead use the rule to define the default
value. Does that work for you?

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: "Gregory S. Williamson"
Date:
Subject: Eliminating bad characters from a database for upgrading from 7.4 to 8.1
Next
From: Jeff Davis
Date:
Subject: explain analyze taking longer than executing the query?