X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 584D4D1C4C7 for ; Sun, 10 Aug 2003 04:51:09 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 22145-06 for ; Sun, 10 Aug 2003 01:49:43 -0300 (ADT) Received: from bugge.potatoe.com (bugge.potatoe.com [216.240.48.15]) by svr1.postgresql.org (Postfix) with ESMTP id 25680D1C4BA for ; Sun, 10 Aug 2003 01:50:56 -0300 (ADT) Received: from potatoe.com (localhost [127.0.0.1]) by bugge.potatoe.com (8.12.9/8.12.2) with ESMTP id h7A4rJaF015671; Sat, 9 Aug 2003 21:53:20 -0700 (PDT) Message-ID: <3F35CFBD.6070607@potatoe.com> Date: Sat, 09 Aug 2003 21:53:17 -0700 From: Brad Bulger Organization: The Madfish Group User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.5b) Gecko/20030727 Thunderbird/0.1 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Bernd Hoffmann , pgsql-php@postgresql.org Subject: Re: functions with plpgsql References: <01b101c35eb3$6e75b2b0$3214a8c0@server> <200308091804.10545.akopciuch@olympusproject.org> <025d01c35ed7$0ad4e590$3214a8c0@server> In-Reply-To: <025d01c35ed7$0ad4e590$3214a8c0@server> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/35 X-Sequence-Number: 2212 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;