From: Tom Lane <tgl@sss.pgh.pa.us>
To: dpandey@secf.com
Cc: 'PostgreSQL' <pgsql-sql@postgresql.org>
Subject: Re: dynamic 'INSERT' query?
Date: Thu, 14 Apr 2005 10:53:14 -0400
Message-ID: <564.1113490394@sss.pgh.pa.us> (raw)
In-Reply-To: <20050414114131.C840B53726@svr1.postgresql.org>
References: <20050414114131.C840B53726@svr1.postgresql.org>
"Dinesh Pandey" <dpandey@secf.com> writes:
> FOR _record IN SELECT A1, A2 FROM A
> LOOP
> _sql := 'INSERT INTO B VALUES (:A1, :A2)';
> EXECUTE (_sql);
Why do you need a dynamic query here at all? You could just do
FOR _record IN SELECT A1, A2 FROM A
LOOP
INSERT INTO B VALUES (_record.A1, _record.A2);
This would be much faster as well as simpler to code.
As far as I can see offhand, you only need EXECUTE when you want to
change table and/or field names from one execution to the next of
a particular query. If you have such a problem, you are omitting
the important details ...
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, dpandey@secf.com
Subject: Re: dynamic 'INSERT' query?
In-Reply-To: <564.1113490394@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox