create insertion rule on view returning id I have a table private.products and a view public.products representing that table. And I want to create entries in private.products while inserting into view, it all works right, except that I also what to return the inserted id:

CREATE RULE insert_product 
AS ON INSERT TO public.products DO INSTEAD 
INSERT INTO private.products (name) VALUES (new.name) RETURNING products.id;
ERROR:  RETURNING list has too few entries


What am I doing wrong?
Without knowing your table and view structure, I created a test case for myself:

CREATE TABLE private_table (
    id serial, 
    col1 text
);


CREATE OR REPLACE VIEW public_view AS 
    SELECT id, col1 
      FROM private;


CREATE OR REPLACE RULE insert_private AS 
    ON INSERT TO public_view DO INSTEAD 
        INSERT INTO private_table (col1) 
        VALUES (new.col1) 
        RETURNING id, col1; -- apparently, this does not work with fewer columns 
                            -- or different ordering


So far, everything works fine, and there is an answer for your question: you have to add all columns of the view in the RETURNING clause of the rule.  

What this does not achieve, though, is turning the INSERT into the view into something that returns the id:

INSERT INTO public_view (col1)
    VALUES ('blah');

INSERT 0 1
-- no id returned!


This absolutely makes sense, and can be avoided by adding the RETURNING clause to the actual INSERT, as usual:

INSERT INTO public_view (col1)
    VALUES ('blah2')
    RETURNING id;

 id 
────
  2
(1 row)

INSERT 0 1