Sample Header Ad - 728x90

Bug in PL/pgSQL function creation

3 votes
2 answers
887 views
I don't know if this question better suits here or in SO ... This is a script that I'd like to launch (the code of the function was copied from a question on SO ): \c mydb create or replace function truncate_tables(username in varchar) returns void as $$ declare stmt RECORD; statements cursor for select tablename from pg_tables where tableowner = username; begin for stmt in statements loop execute 'truncate table ' || quote_ident(stmt.tablename) || ' CASCADE ;'; end loop; end; $$ language 'plpgsql'; I get the following error: ERROR: syntax at or near "$1" LINE1: $1 QUERY $1 CONTEXT: SQL statement in PL/PgSQL function "truncate_tables" near line 5 I am new to Postgres and PL/pgSQL and don't know what this error message means.
Asked by Stephane Rolland (8911 rep)
Aug 22, 2012, 02:28 PM
Last activity: Sep 5, 2012, 02:00 AM