Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 660F39F9259 for ; Wed, 10 Oct 2007 15:52:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 30136-05-2 for ; Wed, 10 Oct 2007 15:52:03 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from pih-relay04.plus.net (pih-relay04.plus.net [212.159.14.131]) by postgresql.org (Postfix) with ESMTP id 22EC09FB6DA for ; Wed, 10 Oct 2007 15:52:08 -0300 (ADT) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay04.plus.net with esmtp (Exim) id 1Ifgf8-0005L6-AT; Wed, 10 Oct 2007 19:52:06 +0100 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 15A68274052; Wed, 10 Oct 2007 19:52:05 +0100 (BST) Message-ID: <470D1F54.6090200@archonet.com> Date: Wed, 10 Oct 2007 19:52:04 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.6 (X11/20070728) MIME-Version: 1.0 To: Ray Madigan CC: Pgsql-Sql Subject: Re: Computed table name in function References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/53 X-Sequence-Number: 29425 Ray Madigan wrote: > I thought that the documentation said I couldn't use EXECUTE on a SELECT > INTO? "37.6.5. Executing Dynamic Commands Oftentimes you will want to generate dynamic commands inside your PL/pgSQL functions, that is, commands that will involve different tables or different data types each time they are executed. PL/pgSQL's normal attempts to cache plans for commands will not work in such scenarios. To handle this sort of problem, the EXECUTE statement is provided: EXECUTE command-string [ INTO [STRICT] target ]; where command-string is an expression yielding a string (of type text) containing the command to be executed and target is a record variable, row variable, or a comma-separated list of simple variables and record/row fields. " There's also a FOR..IN EXECUTE loop too -- Richard Huxton Archonet Ltd