From: | Alban Hertroys <haramrae(at)gmail(dot)com> |
---|---|
To: | leaf_yxj <leaf_yxj(at)163(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Please help me to take a look of the erros in my functions. Thanks. |
Date: | 2012-04-03 06:47:51 |
Message-ID: | F68F09AA-FDEB-4A24-B444-21189FD2D826@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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.
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Smith | 2012-04-03 06:53:24 | Re: Why checkpoint_timeout had maximum value of 1h? |
Previous Message | Alban Hertroys | 2012-04-03 06:45:10 | Re: Please help me to take a look of the erros in my functions. Thanks. |