Re: CREATE RULE fails with 'ERROR: SELECT rule's target list has too many entries' - Mailing list pgsql-general

From Tom Lane
Subject Re: CREATE RULE fails with 'ERROR: SELECT rule's target list has too many entries'
Date
Msg-id 6213.1354723134@sss.pgh.pa.us
Whole thread Raw
In response to Re: CREATE RULE fails with 'ERROR: SELECT rule's target list has too many entries'  (Henrik Kuhn <henrik.kuhn@origenis.de>)
Responses Re: CREATE RULE fails with 'ERROR: SELECT rule's target list has too many entries'
List pgsql-general
Henrik Kuhn <henrik.kuhn@origenis.de> writes:
> On 12/05/2012 04:07 PM, Tom Lane wrote:
>> Henrik Kuhn <henrik.kuhn@origenis.de> writes:
>>> can somebody give me some insights why the creation of this rule fails
>> > with 'ERROR:  SELECT rule's target list has too many entries'?

>> Probably that history_relation has fewer than three columns?  But if
>> you want something more than guessing, you'd have to provide more
>> context, such as the definitions of the underlying tables.  Why are
>> you trying to execute this command anyway?

> The history_relatio-DDL is quite simple:

> CREATE TABLE history_relation (
>      id                  UUID NOT NULL DEFAULT uuid_generate_v4()
>    , relname        name NOT NULL CHECK ( relname::regclass IS NOT NULL
> ) -- use regclass to validate

>    , PRIMARY KEY (id)
> );

> But are your really sure, that the error is thrown just because of there
> are not more than 3 cols in history_relation?

Yes.  I think you misunderstand what that command is for: it's going to
convert the table into a view, and as a safety check it is not allowed
for the resulting view to have a different column set than the table
did.

I think what you need to do is create the underlying table with some
other name, create history_relation as a plain view, and then perhaps
you want some INSTEAD OF triggers on the view to convert insertions
etc into updates of the underlying table.

            regards, tom lane


pgsql-general by date:

Previous
From: Henrik Kuhn
Date:
Subject: Re: CREATE RULE fails with 'ERROR: SELECT rule's target list has too many entries'
Next
From: JP
Date:
Subject: Extending the KD Tree index in Postgresql 9.2.1