From dpandey@secf.com Thu Apr 14 14:31:54 2005 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 3585C53DFD for ; Thu, 14 Apr 2005 11:31: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 84771-08 for ; Thu, 14 Apr 2005 14:31:45 +0000 (GMT) Received: from secf.com (209-128-104-244.bayarea.net [209.128.104.244]) by svr1.postgresql.org (Postfix) with ESMTP id 1704853689 for ; Thu, 14 Apr 2005 11:31:44 -0300 (ADT) Received: from dinesh by secf.com (MDaemon.PRO.v7.2.2.R) with ESMTP id md50000633427.msg for ; Thu, 14 Apr 2005 07:31:18 -0700 Reply-To: From: "Dinesh Pandey" To: "'PostgreSQL'" Subject: Prepared query ? Date: Thu, 14 Apr 2005 19:58:40 +0530 Organization: Second Foundation India P Ltd. MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0040_01C5412C.5CBEECF0" X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Thread-Index: AcVA/kDYtJp2cTBFSmux6F0CMh1A/A== X-Authenticated-Sender: dpandey@secf.com X-Spam-Processed: mail.secf.com, Thu, 14 Apr 2005 07:31:18 -0700 (not processed: message from valid local sender) X-MDRemoteIP: 220.227.32.11 X-Return-Path: dpandey@secf.com X-MDaemon-Deliver-To: pgsql-sql@postgresql.org X-MDAV-Processed: mail.secf.com, Thu, 14 Apr 2005 07:31:20 -0700 Message-Id: <20050414143144.1704853689@svr1.postgresql.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.496 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, HTML_90_100, HTML_MESSAGE, MSGID_FROM_MTA_ID X-Spam-Level: * X-Archive-Number: 200504/191 X-Sequence-Number: 21084 This is a multi-part message in MIME format. ------=_NextPart_000_0040_01C5412C.5CBEECF0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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); END LOOP; Regards Dinesh Pandey ---------------------------------------------------------------------------- ------ Dinesh Pandey Sr. Software Engineer Second Foundation (India) Pvt. Ltd. Plot# 52 Industrial Area, Phase II Chandigarh. (India) PH: (O) 0172-2639202, Extn: 233 ------=_NextPart_000_0040_01C5412C.5CBEECF0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

How can I

  1. Write a prepared = query and
  2. Set values at run = time and
  3. Execute that query = for different values.

 

LOOP<= /p>

     = …..

     = …..

sql = :=3D INSERT INTO MYTABLE VALUES(?, ?);

……<= /span>

--EXECUTE = (sql);

END LOOP;

 

Regards
Dinesh Pandey



-----------------------------------= -----------------------------------------------
<= /font>
Dinesh = Pandey 
Sr. Software Engineer

Second Foundation (India) Pvt. Ltd.
Plot# 52
Industrial Area, Phase II
Chandigarh. (India)
PH: (O) 0172-2639202, Extn: 233

 

------=_NextPart_000_0040_01C5412C.5CBEECF0-- From fbax@sympatico.ca Thu Apr 14 14:54:20 2005 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 168BA53F7E for ; Thu, 14 Apr 2005 11:54:20 -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 96428-01 for ; Thu, 14 Apr 2005 14:54:17 +0000 (GMT) Received: from tomts22-srv.bellnexxia.net (tomts22-srv.bellnexxia.net [209.226.175.184]) by svr1.postgresql.org (Postfix) with ESMTP id 4681E53D83 for ; Thu, 14 Apr 2005 11:54:10 -0300 (ADT) Received: from acer.sympatico.ca ([65.95.168.196]) by tomts22-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20050414145415.JIYQ21470.tomts22-srv.bellnexxia.net@acer.sympatico.ca> for ; Thu, 14 Apr 2005 10:54:15 -0400 Message-Id: <5.2.1.1.0.20050414105247.03e0b420@pop6.sympatico.ca> X-Sender: b1wudu74@pop6.sympatico.ca X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Thu, 14 Apr 2005 10:54:00 -0400 To: pgsql-sql@postgresql.org From: Frank Bax Subject: Re: Prepared query ? In-Reply-To: <20050414143144.1704853689@svr1.postgresql.org> Mime-Version: 1.0 Content-Type: text/html; charset="us-ascii" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.723 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, HTML_40_50, HTML_MESSAGE, MIME_HTML_ONLY X-Spam-Level: X-Archive-Number: 200504/193 X-Sequence-Number: 21086 At 10:28 AM 4/14/05, 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.

Depends on what language you are using - try interfaces mailing list.
From dpandey@secf.com Thu Apr 14 15:01:09 2005 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 6E43053F8B for ; Thu, 14 Apr 2005 12:01:09 -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 97887-06 for ; Thu, 14 Apr 2005 15:01:05 +0000 (GMT) Received: from secf.com (209-128-104-244.bayarea.net [209.128.104.244]) by svr1.postgresql.org (Postfix) with ESMTP id 45A2353F8D for ; Thu, 14 Apr 2005 12:01:04 -0300 (ADT) Received: from dinesh by secf.com (MDaemon.PRO.v7.2.2.R) with ESMTP id md50000633585.msg for ; Thu, 14 Apr 2005 08:00:59 -0700 Reply-To: From: "Dinesh Pandey" To: "'Frank Bax'" , Subject: Re: Prepared query ? Date: Thu, 14 Apr 2005 20:28:20 +0530 Organization: Second Foundation India P Ltd. MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0047_01C54130.821E32E0" X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Thread-Index: AcVBAn/P3W2GC7WuQj2i5p77FsLMdwAACLiQ In-Reply-To: <5.2.1.1.0.20050414105247.03e0b420@pop6.sympatico.ca> X-Authenticated-Sender: dpandey@secf.com X-Spam-Processed: mail.secf.com, Thu, 14 Apr 2005 08:00:59 -0700 (not processed: message from valid local sender) X-MDRemoteIP: 220.227.32.11 X-Return-Path: dpandey@secf.com X-MDaemon-Deliver-To: pgsql-sql@postgresql.org X-MDAV-Processed: mail.secf.com, Thu, 14 Apr 2005 08:01:02 -0700 Message-Id: <20050414150104.45A2353F8D@svr1.postgresql.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.414 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, HTML_MESSAGE, MSGID_FROM_MTA_ID X-Spam-Level: * X-Archive-Number: 200504/196 X-Sequence-Number: 21089 This is a multi-part message in MIME format. ------=_NextPart_000_0047_01C54130.821E32E0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit I am using PL/pgSQL. Thanks Dinesh Pandey _____ From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Frank Bax Sent: Thursday, April 14, 2005 8:24 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Prepared query ? At 10:28 AM 4/14/05, 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. Depends on what language you are using - try interfaces mailing list. ------=_NextPart_000_0047_01C54130.821E32E0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

I am using PL/pgSQL.

 

Thanks

Dinesh Pandey


From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Frank Bax
Sent: Thursday, April 14, = 2005 8:24 PM
To: = pgsql-sql@postgresql.org
Subject: Re: [SQL] = Prepared query ?

 

At 10:28 AM 4/14/05, 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. =


Depends on what language you are using - try interfaces mailing = list.

------=_NextPart_000_0047_01C54130.821E32E0-- From dev@archonet.com Thu Apr 14 14:58:54 2005 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 From dpandey@secf.com Thu Apr 14 15:06:27 2005 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 AA2D953ECD for ; Thu, 14 Apr 2005 12:06:27 -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 01504-04 for ; Thu, 14 Apr 2005 15:06:26 +0000 (GMT) Received: from secf.com (209-128-104-244.bayarea.net [209.128.104.244]) by svr1.postgresql.org (Postfix) with ESMTP id 0A51653603 for ; Thu, 14 Apr 2005 12:06:25 -0300 (ADT) Received: from dinesh by secf.com (MDaemon.PRO.v7.2.2.R) with ESMTP id md50000633599.msg for ; Thu, 14 Apr 2005 08:06:25 -0700 Reply-To: From: "Dinesh Pandey" To: "'Richard Huxton'" Cc: "'PostgreSQL'" Subject: Re: Prepared query ? Date: Thu, 14 Apr 2005 20:33:45 +0530 Organization: Second Foundation India P Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Thread-Index: AcVBAn/P5pzIDE78QCeDH9UWWFs5QAAABr9A In-Reply-To: <425E852D.2020808@archonet.com> X-Authenticated-Sender: dpandey@secf.com X-Spam-Processed: mail.secf.com, Thu, 14 Apr 2005 08:06:25 -0700 (not processed: message from valid local sender) X-MDRemoteIP: 220.227.32.11 X-Return-Path: dpandey@secf.com X-MDaemon-Deliver-To: pgsql-sql@postgresql.org X-MDAV-Processed: mail.secf.com, Thu, 14 Apr 2005 08:06:27 -0700 Message-Id: <20050414150625.0A51653603@svr1.postgresql.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.4 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, MSGID_FROM_MTA_ID X-Spam-Level: * X-Archive-Number: 200504/197 X-Sequence-Number: 21090 Yes you got my problem correctly. I want to change tablename and values at run time. Is there any other way instead using "||" (append) ? like prepared statement. PREPARE fooplan (int, text, bool, numeric) AS INSERT INTO foo VALUES($1, $2, $3, $4); EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00); Thanks Dinesh Pandey -----Original Message----- From: Richard Huxton [mailto:dev@archonet.com] Sent: Thursday, April 14, 2005 8:29 PM To: dpandey@secf.com Cc: 'PostgreSQL' Subject: Re: [SQL] Prepared query ? 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