Re: BUG #10836: Rule with RETURNING claims incorrect type

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: hoschiraffel(at)freenet(dot)de
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #10836: Rule with RETURNING claims incorrect type
Date: 2014-07-02 13:53:37
Message-ID: 1042.1404309217@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

hoschiraffel(at)freenet(dot)de writes:
> test=# create rule test_me_ins as on insert to test_me do instead insert
> into foobar values (new.foo,new.bar) returning (id,info);
> ERROR: 42P17: RETURNING list's entry 1 has different type from column
> "foo"

This is a syntax mistake. What you wrote is equivalent to
returning row(id,info);
so it returns a single composite column rather than the required int and
text columns, so the complaint is correct (if unhelpful :-().
Leave off the parens:
returning id,info;

I'm not sure if there's anything much we could do about improving the
situation. Allowing a row constructor with just parens is required by
SQL standard, but I've seen people confused before by thinking that
outer parens are just syntactic decoration that don't change the meaning
of the expression. Maybe if we just mentioned the two types (record vs
int, in this case) the user's mind would be led in the right direction?

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Matthias Raffelsieper 2014-07-02 14:06:27 Re: BUG #10836: Rule with RETURNING claims incorrect type
Previous Message Marko Tiikkaja 2014-07-02 13:51:23 Re: BUG #10836: Rule with RETURNING claims incorrect type