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 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || '
I think you meant to use a FOR LOOP there, not IF. IF does not know to fetch a record from a CURSOR (hmm... should it
perhaps?).
http://www.postgresql.org/docs/9.1/interactive/plpgsql-cursors.html#PLPGSQL-CURSOR-FOR-LOOP
> CASCADE;';
> ELSE
> The tablename doesn't exist.doesn
> END IF ;
> END;
> $$ LANGUAGE 'plpgsql' security definer;
Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.