Re: pl/pgsql function not working

From: Masaru Sugawara <rk73(at)sea(dot)plala(dot)or(dot)jp>
To: Tom Jenkins <tjenkins(at)devis(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: pl/pgsql function not working
Date: 2002-06-19 15:35:12
Message-ID: 20020620003000.920C.RK73@sea.plala.or.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 19 Jun 2002 09:25:11 -0400
Tom Jenkins <tjenkins(at)devis(dot)com> wrote:

> hello all,
> i hope somebody can shed some light on a problem i'm having with
> pl/pgsql. I need to loop over all my tables and clear out the field
> lastaccess (it was improperly defined as time instead of timestamp)
>
> DROP FUNCTION clear_lastaccess();
> CREATE FUNCTION clear_lastaccess() RETURNS bool AS '
> DECLARE
> obj RECORD;
> BEGIN
> FOR obj IN SELECT relname FROM pg_class WHERE relkind IN (''r'') AND
> relname !~ ''^pg_'' LOOP
> RAISE NOTICE ''update % set lastaccess = NULL;'', obj.relname;
> PERFORM ''update % set lastaccess = NULL;'', obj.relname ;

Try here instead of PERFORM.

EXECUTE ''update '' || obj.relname || '' set lastaccess = NULL;'';

> END LOOP;
> RETURN true;
> END;
> 'LANGUAGE 'plpgsql';
>
> running this function with:
> SELECT clear_lastaccess();
> results in the update statements getting printed but the updates are
> never processed.
>
> looking at my pg log shows the SELECT relname query but no UPDATEs
>
> what do i have wrong?

Regards,
Masaru Sugawara

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Paulo Sergio Fernandes Parola (Keyword) 2002-06-19 15:58:33 unsubscribe
Previous Message Peter de Vroomen 2002-06-19 15:34:38 PQresult() return value not very handy...