Re: [GENERAL] Please help me to take a look of the erros in my functions. Thanks.

2012-04-03 Thread Bartosz Dmytrak
2012/4/3 Alban Hertroys > On 2 Apr 2012, at 22:28, Bartosz Dmytrak wrote: > > > That is right, there is no sense to use cursors here... > > I think you're wrong there: The OP is querying a system table for tables > of a certain name, which I expect can contain multiple rows for tables of > the sa

Re: [GENERAL] Please help me to take a look of the erros in my functions. Thanks.

2012-04-02 Thread Alban Hertroys
On 2 Apr 2012, at 22:02, leaf_yxj wrote: > CREATE OR REPLACE FUNCTION truncate_t(tablename IN VARCHAR) RETURNS void AS > $$ > DECLARE > stmt RECORD; > statements CURSOR FOR SELECT tablename FROM pg_catalog.pg_tables; > BEGIN > IF stmt IN statements then > EXECUTE 'TRUNCAT

Re: [GENERAL] Please help me to take a look of the erros in my functions. Thanks.

2012-04-02 Thread Alban Hertroys
On 2 Apr 2012, at 22:28, Bartosz Dmytrak wrote: > That is right, there is no sense to use cursors here... I think you're wrong there: The OP is querying a system table for tables of a certain name, which I expect can contain multiple rows for tables of the same name in different schema's. Of c

Re: [GENERAL] Please help me to take a look of the erros in my functions. Thanks.

2012-04-02 Thread Bartosz Dmytrak
That is right, there is no sense to use cursors here... CREATE OR REPLACE FUNCTION truncate_t (IN tablename text) RETURNS VOID AS $$ BEGIN EXECUTE 'TRUNCATE TABLE ' || quote_ident(tablename) || 'CASCADE;'; EXCEPTION WHEN undefined_table THEN RAISE EXCEPTION 'Table "%" does not exists', tablename

Re: [GENERAL] Please help me to take a look of the erros in my functions. Thanks.

2012-04-02 Thread Pavel Stehule
Hello " IF stmt IN statements then " is nonsense. use trapping exceptions instead BEGIN EXECUTE 'TRUNCATE TABLE ' || quote_ident(_tablename) || ' CASCADE'; EXCEPTION WHEN undefined_table THEN RAISE EXCEPTION 'your own exception, when you like'; END; Regards Pavel 2012/4/2 leaf_yxj : > I