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

From Dinesh Pandey
Subject dynamic 'INSERT' query?
Date
Msg-id 20050414114131.C840B53726@svr1.postgresql.org
Whole thread Raw
Responses Re: dynamic 'INSERT' query?
Re: dynamic 'INSERT' query?
List pgsql-sql
<div class="Section1"><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt;
font-family:Verdana">How can we set A1, A2 values in dynamic 'INSERT’  query?</span></font><p class="MsoNormal"><font
face="Verdana"size="2"><span style="font-size:10.0pt; 
font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt;
font-family:Verdana">DECLARE</span></font><p class="MsoNormal"><font face="Verdana" size="2"><span
style="font-size:10.0pt;
font-family:Verdana"> _record        RECORD;</span></font><p class="MsoNormal"><font face="Verdana" size="2"><span
style="font-size:10.0pt;
font-family:Verdana"> _sql             VARCHAR(2000);</span></font><p class="MsoNormal"><font face="Verdana"
size="2"><spanstyle="font-size:10.0pt; 
font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt;
font-family:Verdana">FOR _record IN SELECT A1, A2 FROM A</span></font><p class="MsoNormal"><font face="Verdana"
size="2"><spanstyle="font-size:10.0pt;font-family:Verdana">LOOP</span></font><font face="Verdana" size="2"><span
style="font-size:10.0pt;font-family:Verdana"></span></font><pclass="MsoNormal"><font face="Verdana" size="2"><span
style="font-size:10.0pt;
font-family:Verdana"> </span></font><p class="MsoNormal" style="text-indent:.5in"><font face="Verdana" size="2"><span
style="font-size:10.0pt;font-family:Verdana">_sql:= 'INSERT INTO B VALUES (<b><font color="red"><span
style="color:red;font-weight:bold">:A1,:A2</span></font></b>)’;</span></font><p class="MsoNormal"
style="text-indent:.5in"><fontface="Verdana" size="2"><span
style="font-size:10.0pt;font-family:Verdana"> </span></font><pclass="MsoNormal" style="text-indent:.5in"><font
face="Verdana"size="2"><span style="font-size:10.0pt;font-family:Verdana">EXECUTE (_sql);</span></font><p
class="MsoNormal"><fontface="Verdana" size="2"><span style="font-size:10.0pt; 
font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt;
font-family:Verdana">END LOOP;</span></font><p class="MsoNormal"><font face="Verdana" size="2"><span
style="font-size:10.0pt;
font-family:Verdana"> </span></font><p class="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt;
font-family:Verdana">=================================================================</span></font><p
class="MsoNormal"><fontface="Verdana" size="2"><span style="font-size:10.0pt; 
font-family:Verdana">I can do this as (but I need another way instead of using || operator).</span></font><p
class="MsoNormal"><fontface="Verdana" size="2"><span style="font-size:10.0pt; 
font-family:Verdana"> </span></font><p class="MsoNormal" style="text-indent:.5in"><font face="Verdana" size="2"><span
style="font-size:10.0pt;font-family:Verdana">_sql:= 'INSERT INTO B VALUES (‘ || _record.A1 || ’,’ || _record.A2 ||
’)’;</span></font><pclass="MsoNormal"><font face="Verdana" size="2"><span style="font-size:10.0pt; 
font-family:Verdana">=================================================================</span></font><p
class="MsoNormal"><fontface="Verdana" size="2"><span style="font-size:10.0pt; 
font-family:Verdana"> </span></font><p><font face="Verdana" size="2"><span style="font-size:10.0pt">Regards<br />
DineshPandey</span></font><font face="Times New Roman"><span style="font-family: 
"Times New Roman""><br /><br /><br /><b><font color="gray"><span
style="color:gray;font-weight:bold">----------------------------------------------------------------------------------</span></font></b></span></font><br
/><b><fontcolor="gray"><span style="color:gray;font-weight:bold">Dinesh Pandey</span></font></b> <br /><font
color="gray"><spanstyle="color:gray">Sr. Software Engineer<br /><br /></span></font><p class="MsoNormal"><font
face="TimesNew Roman" size="3"><span style="font-size: 
12.0pt"> </span></font></div>

pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Very low performance on table with only 298 rows
Next
From: Andreas Joseph Krogh
Date:
Subject: Re: Very low performance on table with only 298 rows