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;