Jeff Davis <pgsql@j-davis.com> writes:
> 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?
Actually, the best way to do that is to attach a default to the view
itself.
CREATE VIEW v AS SELECT ... ;
CREATE RULE ... for insert on v ... ;
ALTER TABLE v ALTER COLUMN c DEFAULT whatever;
In this formulation the rule is not responsible for substituting any
default values, it just does what it's told. This is better than the
COALESCE approach because the latter does the wrong thing if one is
explicitly inserting NULL.
I'm not sure this answers the OP's problem though, as it sounded like he
wanted a default dependent on other inserted values, which is something
you can't do with either a table or a view.
regards, tom lane