Re: functions with plpgsql

From: Brad Bulger <tater(at)potatoe(dot)com>
To: Bernd Hoffmann <info(at)unixserver(dot)info>, pgsql-php(at)postgresql(dot)org
Subject: Re: functions with plpgsql
Date: 2003-08-10 04:53:17
Message-ID: 3F35CFBD.6070607@potatoe.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Ângelo Marcos Rigo 2003-08-11 17:31:47 Re: Paging results
Previous Message Bernd Hoffmann 2003-08-10 00:33:36 Re: functions with plpgsql