Re: dynamic 'INSERT' query? - Mailing list pgsql-sql

From Tom Lane
Subject Re: dynamic 'INSERT' query?
Date
Msg-id 564.1113490394@sss.pgh.pa.us
Whole thread Raw
In response to dynamic 'INSERT' query?  ("Dinesh Pandey" <dpandey@secf.com>)
Responses Re: dynamic 'INSERT' query?  ("Dinesh Pandey" <dpandey@secf.com>)
List pgsql-sql
"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


pgsql-sql by date:

Previous
From: "Dinesh Pandey"
Date:
Subject: Prepared query ?
Next
From: Frank Bax
Date:
Subject: Re: Prepared query ?