X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 205EF5373E for ; Thu, 14 Apr 2005 11:58:54 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97025-09 for ; Thu, 14 Apr 2005 14:58:52 +0000 (GMT) Received: from anchor-post-32.mail.demon.net (anchor-post-32.mail.demon.net [194.217.242.90]) by svr1.postgresql.org (Postfix) with ESMTP id 63C1653724 for ; Thu, 14 Apr 2005 11:58:51 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-32.mail.demon.net with esmtp (Exim 4.42) id 1DM5nz-000CbF-79; Thu, 14 Apr 2005 14:58:55 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 955E21673D; Thu, 14 Apr 2005 15:58:54 +0100 (BST) Message-ID: <425E852D.2020808@archonet.com> Date: Thu, 14 Apr 2005 15:58:53 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dpandey@secf.com Cc: 'PostgreSQL' Subject: Re: Prepared query ? References: <20050414143144.1704853689@svr1.postgresql.org> In-Reply-To: <20050414143144.1704853689@svr1.postgresql.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.059 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200504/194 X-Sequence-Number: 21087 Dinesh Pandey wrote: > How can I > > 1. Write a prepared query and > 2. Set values at run time and > 3. Execute that query for different values. > LOOP > ….. > ….. > sql := INSERT INTO MYTABLE VALUES(?, ?); > --EXECUTE (sql); You don't say what language you want to use, but assuming it's plpgsql, then for the simple case you can just do: LOOP INSERT INTO mytable VALUES (var1, var2); END LOOP Now, let's say you wanted to change mytable as well as the values, you'd use sql := ''INSERT INTO '' || quote_ident(my_table_variable) || '' VALUES ...etc''; EXECUTE sql; Does that help? -- Richard Huxton Archonet Ltd