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

From Alban Hertroys
Subject Re: Please help me to take a look of the erros in my functions. Thanks.
Date
Msg-id F68F09AA-FDEB-4A24-B444-21189FD2D826@gmail.com
Whole thread Raw
In response to Please help me to take a look of the erros in my functions. Thanks.  (leaf_yxj <leaf_yxj@163.com>)
Responses Re: Please help me to take a look of the erros in my functions. Thanks.  (leaf_yxj <leaf_yxj@163.com>)
List 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.


pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: Please help me to take a look of the erros in my functions. Thanks.
Next
From: Greg Smith
Date:
Subject: Re: Why checkpoint_timeout had maximum value of 1h?