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 2453B5366A for ; Thu, 14 Apr 2005 08:59:13 -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 18971-04 for ; Thu, 14 Apr 2005 11:59:04 +0000 (GMT) Received: from mx5.net.nih.gov (mailfwd.nih.gov [165.112.130.36]) by svr1.postgresql.org (Postfix) with ESMTP id 35057536F6 for ; Thu, 14 Apr 2005 08:59:03 -0300 (ADT) Received: from mx5.net.nih.gov (localhost [127.0.0.1]) by mx5.net.nih.gov (8.12.10/8.11.6) with ESMTP id j3EBx5aq028133 for ; Thu, 14 Apr 2005 07:59:05 -0400 Received: from [128.231.145.14] (holmes.nhgri.nih.gov [128.231.145.14]) by mx5.net.nih.gov (8.12.10/8.11.6) with ESMTP id j3EBx5Kd028130; Thu, 14 Apr 2005 07:59:05 -0400 In-Reply-To: <20050414114131.C840B53726@svr1.postgresql.org> References: <20050414114131.C840B53726@svr1.postgresql.org> Mime-Version: 1.0 (Apple Message framework v619.2) Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Message-Id: Content-Transfer-Encoding: quoted-printable Cc: "'PostgreSQL'" From: Sean Davis Subject: Re: dynamic 'INSERT' query? Date: Thu, 14 Apr 2005 07:59:05 -0400 To: X-Mailer: Apple Mail (2.619.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/189 X-Sequence-Number: 21082 On Apr 14, 2005, at 7:37 AM, Dinesh Pandey wrote: > How can we set A1, A2 values in dynamic 'INSERT=92 =A0query? > > =A0 > > DECLARE > > =A0_record =A0=A0=A0=A0=A0=A0 RECORD; > > =A0_sql=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 VARCHAR(2000); > > =A0 > > FOR _record IN SELECT A1, A2 FROM A > > LOOP > > =A0 > > _sql :=3D 'INSERT INTO B VALUES (:A1, :A2)=92; > > =A0 > > EXECUTE (_sql); > > =A0 > > END LOOP; > > =A0 > > =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). > > =A0 > > _sql :=3D 'INSERT INTO B VALUES (=91 || _record.A1 || =92,=92 || = _record.A2 ||=20 > =92)=92; > Dinesh, I think what you are showing here IS the way to build up a dynamic sql=20= statement. I'm not sure that you can write a prepared statement within=20= the body of a function, which would then look more like what you are=20 suggesting you want to do--perhaps others on the list can enlighten us=20= about that. In any case, why won't using the || operator work for you? Sean