Re: functions with plpgsql - Mailing list pgsql-php

From Brad Bulger
Subject Re: functions with plpgsql
Date
Msg-id 3F35CFBD.6070607@potatoe.com
Whole thread Raw
In response to Re: functions with plpgsql  ("Bernd Hoffmann" <info@unixserver.info>)
List pgsql-php

Bernd Hoffmann wrote:

> Hallo Andy,
>
>
>>I do not think you can evaluate a declared vairable as a table name in the
>>SELECT statement.
>
>
> where can I find some docu about declare a table by variable.

you need to do this as a dynamic query.

look in the pl/pgsql docs here
http://www.postgresql.org/docs/7.3/interactive/plpgsql-statements.html
and here
http://www.postgresql.org/docs/7.3/interactive/plpgsql-control-structures.html
for description of the FOR-IN-EXECUTE loop you need for dynamic SELECTs

basically it'll be something like

FOR myrecordvar IN EXECUTE ''select max(id) from '' ||
quote_ident(mytablenamevar) LOOP
    ... do some stuff ...
END LOOP;



pgsql-php by date:

Previous
From: "Bernd Hoffmann"
Date:
Subject: Re: functions with plpgsql
Next
From: Ângelo Marcos Rigo
Date:
Subject: Re: Paging results