Connecting Tech Pros Worldwide Forums | Help | Site Map

Urgent: Input of values to execute dynamic queries

Jack Bauer
Guest
 
Posts: n/a
#1: Nov 23 '05
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?

HansH
Guest
 
Posts: n/a
#2: Nov 23 '05

re: Urgent: Input of values to execute dynamic queries


"Jack Bauer" <giuffsalvo@softhome.net> schreef in bericht
news:5o99l0ldhr5i6p89ibb663gv5pmqolq2gm@4ax.com...[color=blue]
> 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?[/color]
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







Closed Thread


Similar PostgreSQL Database bytes