pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedPrepared query ?
5+ messages / 3 participants
[nested] [flat]
* Prepared query ?
@ 2005-04-14 14:28 Dinesh Pandey <dpandey@secf.com>
0 siblings, 2 replies; 5+ messages in thread
From: Dinesh Pandey @ 2005-04-14 14:28 UTC (permalink / raw)
To: pgsql-sql
How can I
1. Write a prepared query and
2. Set values at run time and
3. Execute that query for different values.
LOOP
...
...
sql := INSERT INTO MYTABLE VALUES(?, ?);
..
--EXECUTE (sql);
END LOOP;
Regards
Dinesh Pandey
----------------------------------------------------------------------------
------
Dinesh Pandey
Sr. Software Engineer
Second Foundation (India) Pvt. Ltd.
Plot# 52
Industrial Area, Phase II
Chandigarh. (India)
PH: (O) 0172-2639202, Extn: 233
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Prepared query ?
@ 2005-04-14 14:54 Frank Bax <fbax@sympatico.ca>
parent: Dinesh Pandey <dpandey@secf.com>
1 sibling, 1 reply; 5+ messages in thread
From: Frank Bax @ 2005-04-14 14:54 UTC (permalink / raw)
To: pgsql-sql
<html>
<body>
At 10:28 AM 4/14/05, Dinesh Pandey wrote:<br>
<blockquote type=cite class=cite cite><font face="verdana" size=2>How can
I
<ol>
<li>Write a prepared query and
<li>Set values at run time and
<li>Execute that query for different values.</font> </blockquote>
</ol><br>
Depends on what language you are using - try interfaces mailing
list.<br>
</body>
</html>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Prepared query ?
@ 2005-04-14 14:58 Dinesh Pandey <dpandey@secf.com>
parent: Frank Bax <fbax@sympatico.ca>
0 siblings, 0 replies; 5+ messages in thread
From: Dinesh Pandey @ 2005-04-14 14:58 UTC (permalink / raw)
To: 'Frank Bax' <fbax@sympatico.ca>; pgsql-sql
I am using PL/pgSQL.
Thanks
Dinesh Pandey
_____
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of Frank Bax
Sent: Thursday, April 14, 2005 8:24 PM
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] Prepared query ?
At 10:28 AM 4/14/05, Dinesh Pandey wrote:
How can I
1. Write a prepared query and
2. Set values at run time and
3. Execute that query for different values.
Depends on what language you are using - try interfaces mailing list.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Prepared query ?
@ 2005-04-14 14:58 Richard Huxton <dev@archonet.com>
parent: Dinesh Pandey <dpandey@secf.com>
1 sibling, 1 reply; 5+ messages in thread
From: Richard Huxton @ 2005-04-14 14:58 UTC (permalink / raw)
To: dpandey@secf.com; +Cc: pgsql-sql
Dinesh Pandey wrote:
> How can I
>
> 1. Write a prepared query and
> 2. Set values at run time and
> 3. Execute that query for different values.
> LOOP
> …..
> …..
> sql := INSERT INTO MYTABLE VALUES(?, ?);
> --EXECUTE (sql);
You don't say what language you want to use, but assuming it's plpgsql,
then for the simple case you can just do:
LOOP
INSERT INTO mytable VALUES (var1, var2);
END LOOP
Now, let's say you wanted to change mytable as well as the values, you'd use
sql := ''INSERT INTO '' || quote_ident(my_table_variable) || ''
VALUES ...etc'';
EXECUTE sql;
Does that help?
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Prepared query ?
@ 2005-04-14 15:03 Dinesh Pandey <dpandey@secf.com>
parent: Richard Huxton <dev@archonet.com>
0 siblings, 0 replies; 5+ messages in thread
From: Dinesh Pandey @ 2005-04-14 15:03 UTC (permalink / raw)
To: 'Richard Huxton' <dev@archonet.com>; +Cc: pgsql-sql
Yes you got my problem correctly. I want to change tablename and values at
run time.
Is there any other way instead using "||" (append) ? like prepared
statement.
PREPARE fooplan (int, text, bool, numeric) AS
INSERT INTO foo VALUES($1, $2, $3, $4);
EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00);
Thanks
Dinesh Pandey
-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: Thursday, April 14, 2005 8:29 PM
To: dpandey@secf.com
Cc: 'PostgreSQL'
Subject: Re: [SQL] Prepared query ?
Dinesh Pandey wrote:
> How can I
>
> 1. Write a prepared query and
> 2. Set values at run time and
> 3. Execute that query for different values.
> LOOP
> ...
> ...
> sql := INSERT INTO MYTABLE VALUES(?, ?);
> --EXECUTE (sql);
You don't say what language you want to use, but assuming it's plpgsql,
then for the simple case you can just do:
LOOP
INSERT INTO mytable VALUES (var1, var2);
END LOOP
Now, let's say you wanted to change mytable as well as the values, you'd use
sql := ''INSERT INTO '' || quote_ident(my_table_variable) || ''
VALUES ...etc'';
EXECUTE sql;
Does that help?
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2005-04-14 15:03 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-14 14:28 Prepared query ? Dinesh Pandey <dpandey@secf.com>
2005-04-14 14:54 ` Frank Bax <fbax@sympatico.ca>
2005-04-14 14:58 ` Dinesh Pandey <dpandey@secf.com>
2005-04-14 14:58 ` Richard Huxton <dev@archonet.com>
2005-04-14 15:03 ` Dinesh Pandey <dpandey@secf.com>
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