user1759572
user1759572

Reputation: 683

Postgres trigger based partitioning, insert NEW.* gives values (10,,,)

I am doing Postgresql partitioning and I have such insert in the trigger:

EXECUTE 'INSERT INTO ' || tablename || ' VALUES ' || NEW.*;

When I am inserting partial data (with default values)

INSERT INTO my_table(id, col) VALUES (1, 10); 

to a table with a trigger I get an syntax error because the EXECUTE statement in the trigger builds such an insert sql statement (error by continued commas):

 INSERT INTO my_table_p3 VALUES (1,10,,,,)

How can I solve an error? P.S. I have ~300 columns in my table.

Upvotes: 0

Views: 365

Answers (1)

Daniel Vérité
Daniel Vérité

Reputation: 61546

The proper syntax for this construct on a reasonably recent version of PostgreSQL would be:

 EXECUTE 'INSERT INTO ' || tablename || ' VALUES ($1.*)'
   USING NEW;

Upvotes: 1

Related Questions