From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Eric B(dot) Ridge" <ebr(at)tcdi(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Fwd: REWRITE_INVOKE_MAX and "query may contain cycles" |
Date: | 2003-02-21 03:20:14 |
Message-ID: | 2891.1045797614@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Eric B. Ridge" <ebr(at)tcdi(dot)com> writes:
> INSERT INTO foo (id, title, type) VALUES (<default>, 'whatever',
> <default>);
> Is there no keyword for getting the DEFAULT value of a column when
> doing an INSERT?
Not sure how far back this goes, but in 7.3 you can say DEFAULT:
INSERT INTO foo (id, title, type) VALUES (default, 'whatever',
default);
which is per SQL spec.
> Alternatively, it would be really sweet if ON INSERT RULEs would
> provide the DEFAULT values in NEW for those fields that weren't
> specified in the triggering INSERT statement.
Again, I don't recall when we implemented this, but you can attach
column default values to views in 7.3, and maybe before. In your
example:
> CREATE VIEW foo_view AS SELECT * FROM foo;
> CREATE RULE foo_rule ON INSERT TO foo_view DO INSTEAD (
> INSERT INTO some_other_table (id, title, type) values (NEW.id,
> NEW.title, NEW.type)
> );
> INSERT INTO foo_view (title) values ('whatever');
the unspecified columns will be driven by any column defaults attached
to foo_view (not foo). You say, eg,
alter table foo_view alter column id set default nextval('seq_foo_id');
and away you go.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Stephen Robert Norris | 2003-02-21 03:48:24 | Bit string storage space? |
Previous Message | Eric B.Ridge | 2003-02-21 02:36:32 | Re: Fwd: REWRITE_INVOKE_MAX and "query may contain cycles" |