pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
dinamic sql
2+ messages / 2 participants
[nested] [flat]

* dinamic sql
@ 2006-08-29 10:31  Manso Gomez, Ramon <rmgomez@indra.es>
  0 siblings, 1 reply; 2+ messages in thread

From: Manso Gomez, Ramon @ 2006-08-29 10:31 UTC (permalink / raw)
  To: pgsql-sql

Hi

I need to write a Postgres function which executes a cursor. Query of
this cursor however is created on the basis of parameters passed by
user.


if(user_Input = 'a')
l_query := l_query||a_from_clause ||'where ename in '||user_Input
else
if(user_Input = 'b')
l_query := l_query||b_from_clause||'where ename in '||user_Input

OPEN csr FOR l_query;


How do we do it is postgres. My problem I know how to pass parameters
like "ename=parameter", but If the SQL sentence is  ename in
(parameters). It does not work.

Thanx in Advance.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: dinamic sql
@ 2006-08-29 12:33  Jaime Casanova <systemguards@gmail.com>
  parent: Manso Gomez, Ramon <rmgomez@indra.es>
  0 siblings, 0 replies; 2+ messages in thread

From: Jaime Casanova @ 2006-08-29 12:33 UTC (permalink / raw)
  To: Manso Gomez, Ramon <rmgomez@indra.es>; +Cc: pgsql-sql

On 8/29/06, Manso Gomez, Ramon <rmgomez@indra.es> wrote:
>
> if(user_Input = 'a')
> l_query := l_query||a_from_clause ||'where ename in '||user_Input
> else
> if(user_Input = 'b')
> l_query := l_query||b_from_clause||'where ename in '||user_Input
>
> OPEN csr FOR l_query;
>

l_query := l_query || a_from_clause
                              || 'where ename in (' ||
quote_literal(user_input) || ')'

-- 
regards,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
                                       Richard Cook



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2006-08-29 12:33 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-29 10:31 dinamic sql Manso Gomez, Ramon <rmgomez@indra.es>
2006-08-29 12:33 ` Jaime Casanova <systemguards@gmail.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