Re: dynamic 'INSERT' query?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: dpandey(at)secf(dot)com
Cc: "'PostgreSQL'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: dynamic 'INSERT' query?
Date: 2005-04-14 14:53:14
Message-ID: 564.1113490394@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Dinesh Pandey" <dpandey(at)secf(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Frank Bax 2005-04-14 14:54:00 Re: Prepared query ?
Previous Message Dinesh Pandey 2005-04-14 14:28:40 Prepared query ?