Re: postgre variable

From: Volkan YAZICI <volkan(dot)yazici(at)gmail(dot)com>
To: bandeng <postgredb(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: postgre variable
Date: 2005-05-19 07:42:32
Message-ID: 7104a7370505190042692d6649@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

On 5/19/05, bandeng <postgredb(at)gmail(dot)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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message KÖPFERL Robert 2005-05-19 07:53:10 Re: Meaning of ERROR: tuple concurrently updated
Previous Message Richard Huxton 2005-05-19 06:55:45 Re: postgre variable