Re: [GENERAL] Concatenate table name in Pl/Pgsql

2013-06-26 Thread Adarsh Sharma
Able to fix but still new error :( test=# CREATE OR REPLACE FUNCTION tmp_trigger_function() test-# RETURNS TRIGGER AS $$ test$# DECLARE test$# stmt text; test$# abc varchar; test$# BEGIN test$# select to_char(NEW.a::timestamp,'mmdd') into abc ; test$# stmt := 'insert into tmp'||abc|| '

Re: [GENERAL] Concatenate table name in Pl/Pgsql

2013-06-26 Thread Adarsh Sharma
Final Fix : execute 'insert into tmp'||abc|| ' select $1.*' using new; Thanks On Wed, Jun 26, 2013 at 12:18 PM, Adarsh Sharma eddy.ada...@gmail.comwrote: Able to fix but still new error :( test=# CREATE OR REPLACE FUNCTION tmp_trigger_function() test-# RETURNS TRIGGER AS $$ test$#

[GENERAL] Concatenate table name in Pl/Pgsql

2013-06-25 Thread Adarsh Sharma
Hi , Today i m creating a function that includes dynamic concatenation of a partitioned table name as below :- test=# CREATE OR REPLACE FUNCTION tmp_trigger_function() test-# RETURNS TRIGGER AS $$ test$# DECLARE test$# tbl_name text; test$# abc varchar; test$# BEGIN test$# tbl_name := 'tmp';

Re: [GENERAL] Concatenate table name in Pl/Pgsql

2013-06-25 Thread Adarsh Sharma
EXECUTE 'insert into tmp'||abc|| 'values ( NEW.* )'; This works :)

Re: [GENERAL] Concatenate table name in Pl/Pgsql

2013-06-25 Thread Ian Lawrence Barwick
2013/6/26 Adarsh Sharma eddy.ada...@gmail.com: Hi , Today i m creating a function that includes dynamic concatenation of a partitioned table name as below :- test=# CREATE OR REPLACE FUNCTION tmp_trigger_function() test-# RETURNS TRIGGER AS $$ test$# DECLARE test$# tbl_name text; test$#

Re: [GENERAL] Concatenate table name in Pl/Pgsql

2013-06-25 Thread Adarsh Sharma
Thanks Ian for such a quick response. But my NEW.* will be 10-15 columns row. test=# CREATE OR REPLACE FUNCTION tmp_trigger_function() test-# RETURNS TRIGGER AS $$ test$# DECLARE test$# stmt text; test$# abc varchar; test$# BEGIN test$# select to_char(NEW.a::timestamp,'mmdd') into abc ;

Re: [GENERAL] Concatenate table name in Pl/Pgsql

2013-06-25 Thread Ian Lawrence Barwick
Thanks On Wed, Jun 26, 2013 at 10:52 AM, Ian Lawrence Barwick barw...@gmail.com wrote: 2013/6/26 Adarsh Sharma eddy.ada...@gmail.com: Hi , Today i m creating a function that includes dynamic concatenation of a partitioned table name as below :- test=# CREATE OR REPLACE FUNCTION

Re: [GENERAL] Concatenate table name in Pl/Pgsql

2013-06-25 Thread Adarsh Sharma
Passing each column seems not good because if column additon/deletion happens in future , we also need to change function as well. I think below will work :- test=# CREATE OR REPLACE FUNCTION tmp_trigger_function() test-# RETURNS TRIGGER AS $$ test$# DECLARE test$# abc varchar; test$# BEGIN