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 8F5E153734 for ; Thu, 14 Apr 2005 08:41:40 -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 12322-05 for ; Thu, 14 Apr 2005 11:41:34 +0000 (GMT) Received: from secf.com (209-128-104-244.bayarea.net [209.128.104.244]) by svr1.postgresql.org (Postfix) with ESMTP id C840B53726 for ; Thu, 14 Apr 2005 08:41:31 -0300 (ADT) Received: from dinesh by secf.com (MDaemon.PRO.v7.2.2.R) with ESMTP id md50000632816.msg for ; Thu, 14 Apr 2005 04:40:32 -0700 Reply-To: From: "Dinesh Pandey" To: "'PostgreSQL'" Subject: dynamic 'INSERT' query? Date: Thu, 14 Apr 2005 17:07:54 +0530 Organization: Second Foundation India P Ltd. MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0025_01C54114.815D64A0" X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Thread-Index: AcVA5mVy32wnVP7MThavkPaeQwA55w== X-Authenticated-Sender: dpandey@secf.com X-Spam-Processed: mail.secf.com, Thu, 14 Apr 2005 04:40:32 -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 04:40:32 -0700 Message-Id: <20050414114131.C840B53726@svr1.postgresql.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.502 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, HTML_MESSAGE, MSGID_FROM_MTA_ID, UPPERCASE_25_50 X-Spam-Level: * X-Archive-Number: 200504/187 X-Sequence-Number: 21080 This is a multi-part message in MIME format. ------=_NextPart_000_0025_01C54114.815D64A0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit How can we set A1, A2 values in dynamic 'INSERT' query? DECLARE _record RECORD; _sql VARCHAR(2000); FOR _record IN SELECT A1, A2 FROM A LOOP _sql := 'INSERT INTO B VALUES (:A1, :A2)'; EXECUTE (_sql); END LOOP; ================================================================= I can do this as (but I need another way instead of using || operator). _sql := 'INSERT INTO B VALUES (' || _record.A1 || ',' || _record.A2 || ')'; ================================================================= Regards Dinesh Pandey ---------------------------------------------------------------------------- ------ Dinesh Pandey Sr. Software Engineer ------=_NextPart_000_0025_01C54114.815D64A0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

How can we set A1, A2 values in dynamic = 'INSERT’  query?

 

DECLARE

 _record        = RECORD;

 _sql       =       = VARCHAR(2000);

 

FOR _record IN SELECT A1, A2 FROM = A

LOOP<= /p>

 

_sql :=3D 'INSERT INTO B = VALUES (:A1, = :A2)’;

 

EXECUTE = (_sql);

 

END LOOP;

 

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

I can do this as (but I need another way instead of = using || operator).

 

_sql :=3D 'INSERT INTO B = VALUES (‘ || _record.A1 || ’,’ || _record.A2 || = ’)’;

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

 

Regards
Dinesh Pandey



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

 

------=_NextPart_000_0025_01C54114.815D64A0--