pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Volkan YAZICI <volkan.yazici@gmail.com>
To: bandeng <postgredb@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: postgre variable
Date: Thu, 19 May 2005 10:42:32 +0300
Message-ID: <7104a7370505190042692d6649@mail.gmail.com> (raw)
In-Reply-To: <3817e22905051819111a04c2fe@mail.gmail.com>
References: <3817e22905051819111a04c2fe@mail.gmail.com>

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.



view thread (4+ messages)  latest in thread

Message-ID: <7104a7370505190042692d6649@mail.gmail.com>
Permalink:  ../7104a7370505190042692d6649@mail.gmail.com/
Also on:    postgresql.org/message-id/7104a7370505190042692d6649@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: volkan.yazici@gmail.com, postgredb@gmail.com
  Subject: Re: postgre variable
  In-Reply-To: <7104a7370505190042692d6649@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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