Please help me to take a look of the erros in my functions. Thanks. - Mailing list pgsql-general

From leaf_yxj
Subject Please help me to take a look of the erros in my functions. Thanks.
Date
Msg-id 1333396922396-5613507.post@n5.nabble.com
Whole thread Raw
Responses Re: Please help me to take a look of the erros in my functions. Thanks.
Re: Please help me to take a look of the erros in my functions. Thanks.
List pgsql-general
I tried to create function to truncate table
1) when the user call the function just specify the tablename
2) the user can use the function owner privilege to execute the function.

But I got the errors as follows. Please help me to take a look.

Thanks.

Regards.

Grace
------ function :

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 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || '
CASCADE;';
 ELSE
     The tablename doesn't exist.doesn
     END IF ;
 END;
 $$ LANGUAGE 'plpgsql' security definer;

---- errors.
ERROR:  syntax error at or near "$2"
LINE 1: SELECT   $1  IN  $2
                         ^
QUERY:  SELECT   $1  IN  $2
CONTEXT:  SQL statement in PL/PgSQL function "truncate_t" near line 6

--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Please-help-me-to-take-a-look-of-the-erros-in-my-functions-Thanks-tp5613507p5613507.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

pgsql-general by date:

Previous
From: Bartosz Dmytrak
Date:
Subject: Re: How to check the role has been granted to which role. Help me to double check . Thanks.
Next
From: Pavel Stehule
Date:
Subject: Re: Please help me to take a look of the erros in my functions. Thanks.