Re: Behavior of parameter holders in query containing a '$1'

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Eddy Hahn <EDDYH(at)CREIGHTONEDWARD(dot)COM>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Behavior of parameter holders in query containing a '$1'
Date: 2010-09-28 21:51:57
Message-ID: 29669.1285710717@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Eddy Hahn <EDDYH(at)CREIGHTONEDWARD(dot)COM> writes:
> 1) I'm reading the API documentation and I'm wondering how the client library would handle the following statement

> INSERT INTO test (value1, value2) VALUES ('$1', $1)

> Would it handle it incorrectly and would think that '$1' is the parameter or would it skip it because it know that it's a string value encapsulated in ''?

It should think that that's the literal constant dollarsign-one. That
will definitely work as expected if the client library is relying on
server-side parameter substitution. There have been versions of some
client libraries that did their own textual parameter substitution,
before the server-side facility existed. It's at least theoretically
possible that one of those would've got it wrong, but I've not heard
of actual cases.

> 2) Can $1 be used more then one times for example if you want to use the same value for multiple column value?
> UPDATE test set value1=$1,value2=$1

Sure.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2010-09-28 22:07:00 Re: Exclusion constraint issue
Previous Message Bruce Momjian 2010-09-28 21:49:10 Re: pg_upgrade