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

* postgre variable
@ 2005-05-19 02:11 bandeng <postgredb@gmail.com>
  2005-05-19 06:55 ` Re: postgre variable Richard Huxton <dev@archonet.com>
  2005-05-19 07:42 ` Re: postgre variable Volkan YAZICI <volkan.yazici@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: bandeng @ 2005-05-19 02:11 UTC (permalink / raw)
  To: pgsql-sql

hello all,

i want to make dynamic sql query like this

select * from tb_cust where name='erick' and age='20'

to

select * from tb_cust $1

i have tried but error comeup

any suggestion?

thanks
Ricky
-- 
Gutten Aben Sugeng Sonten, Jangane Kurang Santen
bandeng....................



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

* Re: postgre variable
  2005-05-19 02:11 postgre variable bandeng <postgredb@gmail.com>
@ 2005-05-19 06:55 ` Richard Huxton <dev@archonet.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Richard Huxton @ 2005-05-19 06:55 UTC (permalink / raw)
  To: bandeng <postgredb@gmail.com>; +Cc: pgsql-sql

bandeng wrote:
> hello all,
> 
> i want to make dynamic sql query like this
> 
> select * from tb_cust where name='erick' and age='20'
> 
> to
> 
> select * from tb_cust $1
> 
> i have tried but error comeup

You have tried what? How? What error did you get?

-- 
   Richard Huxton
   Archonet Ltd



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

* Re: postgre variable
  2005-05-19 02:11 postgre variable bandeng <postgredb@gmail.com>
@ 2005-05-19 07:42 ` Volkan YAZICI <volkan.yazici@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Volkan YAZICI @ 2005-05-19 07:42 UTC (permalink / raw)
  To: bandeng <postgredb@gmail.com>; +Cc: pgsql-sql

Hi,

On 5/19/05, bandeng <postgredb@gmail.com> wrote:
> i want to make dynamic sql query like this
> 
> select * from tb_cust where name='erick' and age='20'
> 
> to
> 
> select * from tb_cust $1
> 
> i have tried but error comeup

I think there's a confusion about the usage of parameters like $1, $2,
... etc. You cannot use parameters for a whole statement like "where
name='erick' and age='20'" or "name='erick'". It's only useful to
point returned fields. Namely, above SQL query should be:

SELECT * FROM tb_cust WHERE name = $1 AND age = $2;

Plus beware it doesn't need quotes around parameter. Moreover, if
you're using some PostgreSQL API, you don't need to escape data
inserted by parameters. You may refer to documentation for further
information.

Regards.



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

* Re: postgre variable
@ 2005-05-19 09:11 KÖPFERL Robert <robert.koepferl@sonorys.at>
  0 siblings, 0 replies; 4+ messages in thread

From: KÖPFERL Robert @ 2005-05-19 09:11 UTC (permalink / raw)
  To: 'bandeng' <postgredb@gmail.com>; pgsql-sql

You should considder a variation as Volkan suggested.

Otherwise the EXECUTE command might be what you are looking for.
Execute a sql made up in a string

|-----Original Message-----
|From: bandeng [mailto:postgredb@gmail.com]
|Sent: Donnerstag, 19. Mai 2005 04:11
|To: pgsql-sql@postgresql.org
|Subject: [SQL] postgre variable
|
|
|hello all,
|
|i want to make dynamic sql query like this
|
|select * from tb_cust where name='erick' and age='20'
|
|to
|
|select * from tb_cust $1
|
|i have tried but error comeup
|
|any suggestion?
|
|thanks
|Ricky
|-- 
|Gutten Aben Sugeng Sonten, Jangane Kurang Santen
|bandeng....................
|
|---------------------------(end of 
|broadcast)---------------------------
|TIP 9: the planner will ignore your desire to choose an index 
|scan if your
|      joining column's datatypes do not match
|



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


end of thread, other threads:[~2005-05-19 09:11 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-05-19 02:11 postgre variable bandeng <postgredb@gmail.com>
2005-05-19 06:55 ` Richard Huxton <dev@archonet.com>
2005-05-19 07:42 ` Volkan YAZICI <volkan.yazici@gmail.com>
2005-05-19 09:11 Re: postgre variable KÖPFERL Robert <robert.koepferl@sonorys.at>

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