BUG #5400: Columns count mismatch in RULE with subquery

Started by Teodor Buchnerabout 16 years ago2 messagesbugs
Jump to latest
#1Teodor Buchner
t.buchner@autoguard.pl

The following bug has been logged online:

Bug reference: 5400
Logged by: Teodor Buchner
Email address: t.buchner@autoguard.pl
PostgreSQL version: 8.4.1
Operating system: Linux
Description: Columns count mismatch in RULE with subquery
Details:

When SELECT INSERT syntax is used to pump data in a rule, an error appears
during creation of this rule if only SELECT has more than one argument.
ERROR: INSERT has more target columns than expressions
Stan SQL:42601
Znak:137

CREATE OR REPLACE RULE move_iteration_1 AS ON INSERT TO a.iteration DO ALSO

INSERT INTO b.iteration(id,date_period_begin)
SELECT (NEW.id,NEW.date_period_begin) FROM a.iteration;

The example is dummy as INSERT VALUES can be used here but it is impossible
to build any complex subquery instead. Reduction to a single variable
(removing date_period_begin from INSERT/SELECT) removes this error.
Rgds
TB

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Teodor Buchner (#1)
Re: BUG #5400: Columns count mismatch in RULE with subquery

"Teodor Buchner" <t.buchner@autoguard.pl> writes:

CREATE OR REPLACE RULE move_iteration_1 AS ON INSERT TO a.iteration DO ALSO

INSERT INTO b.iteration(id,date_period_begin)
SELECT (NEW.id,NEW.date_period_begin) FROM a.iteration;

Your use of parentheses in the SELECT targetlist is incorrect (and would
be with or without the RULE context). What this is trying to do is
insert a single composite column into the target table. You want

INSERT INTO b.iteration(id,date_period_begin)
SELECT NEW.id,NEW.date_period_begin FROM a.iteration;

regards, tom lane