dbTalk Databases Forums  

Urgent: Input of values to execute dynamic queries

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss Urgent: Input of values to execute dynamic queries in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jack Bauer
 
Posts: n/a

Default Urgent: Input of values to execute dynamic queries - 09-24-2005 , 06:55 PM






How can I execute a query which prompt the user for input?
Something like
SELECT [target list]
FROM Table
WHERE Name=[value input from user]

In Oracle PL/SQL, you use & before variable names to have the SQL*Plus
ask for input.
In Postgres PLpg/SQL, I read that the EXECUTE statement should let you
do something like this, but I tried
EXECUTE 'SELECT * FROM Employeers WHERE id=' || quote_literal(emp_id);
and the psql client tells me
ERROR: syntax error at or near "'SELECT * FROM Employeers WHERE id='"
at character 9
LINE 1: EXECUTE 'SELECT *.....
^
Could you help me, please?

Reply With Quote
  #2  
Old   
HansH
 
Posts: n/a

Default Re: Urgent: Input of values to execute dynamic queries - 09-25-2005 , 07:14 AM






"Jack Bauer" <giuffsalvo (AT) softhome (DOT) net> schreef in bericht
news:5o99l0ldhr5i6p89ibb663gv5pmqolq2gm (AT) 4ax (DOT) com...
Quote:
How can I execute a query which prompt the user for input?
Something like
SELECT [target list]
FROM Table
WHERE Name=[value input from user]

In Oracle PL/SQL, you use & before variable names to have the SQL*Plus
ask for input.
In Postgres PLpg/SQL, I read that the EXECUTE statement should let you
do something like this, but I tried
EXECUTE 'SELECT * FROM Employeers WHERE id=' || quote_literal(emp_id);
and the psql client tells me
ERROR: syntax error at or near "'SELECT * FROM Employeers WHERE id='"
at character 9
LINE 1: EXECUTE 'SELECT *.....
^
Could you help me, please?
Straight from the manual -7.4 and above-,
you have to prepare before execute:
PREPARE usrrptplan (int, date) AS
SELECT * FROM users u, logs l WHERE u.usrid=$1
AND u.usrid=l.usrid AND l.date = $2;
EXECUTE usrrptplan(1, current_date);

Still, ' EXECUTE usrrptplan ' will not prompt you for input.

HansH









Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.