public inbox for [email protected]  
help / color / mirror / Atom feed
PREPARE statement example error.
2+ messages / 2 participants
[nested] [flat]

* PREPARE statement example error.
@ 2004-10-29 18:37  Wood, Bruce <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Wood, Bruce @ 2004-10-29 18:37 UTC (permalink / raw)
  To: pgsql-docs

There is an error in your example for the prepare statement on page http://developer.postgresql.org/docs/postgres/sql-prepare.html.

Using the example from the link above

rainstorm=> PREPARE fooplan (int, text, bool, numeric(8,2)) AS
rainstorm->     INSERT INTO foo VALUES($1, '$2', '$3', '$4');
ERROR:  invalid input syntax for type boolean: "$3"

Taking out the single quotes around the boolean parameter 3 yields

rainstorm=> PREPARE fooplan (int, text, bool, numeric(8,2)) AS
rainstorm->     INSERT INTO foo VALUES($1, '$2', $3, '$4');
ERROR:  invalid input syntax for type real: "$4"

So take out the single quotes around the numeric parameter 4 yields

rainstorm=> PREPARE fooplan (int, text, bool, numeric(8,2)) AS
rainstorm->     INSERT INTO foo VALUES($1, '$2', $3, $4);
PREPARE
rainstorm=> EXECUTE fooplan(1, 'Hunter Valley', 't', '200.00');
INSERT 0 1

So that "works", but what it does is

rainstorm=> select * from foo;
 key | address | valid | cost
-----+---------+-------+------
   1 | $2      | t     |  200
(1 row)

It inserts the literal string of parameter two rather than the value provided for parameter 2.  This is in the PostgreSQL 8 beta 4 Windows native version.

Bruce Wood			Reception (301) 373-2360  
Northrop Grumman PRB Systems	Voice Mail (301) 373-2388 ext 2151
43865 Airport View Drive		Fax           (301) 373-2398
Hollywood, MD 20636		Email         [email protected]






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

* Re: PREPARE statement example error.
@ 2004-10-29 19:41  Tom Lane <[email protected]>
  parent: Wood, Bruce <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2004-10-29 19:41 UTC (permalink / raw)
  To: Wood, Bruce <[email protected]>; +Cc: pgsql-docs

"Wood, Bruce" <[email protected]> writes:
> There is an error in your example for the prepare statement on page http://developer.postgresql.org/docs/postgres/sql-prepare.html.

Good catch --- none of those quotes should be there.  Thanks.

			regards, tom lane




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


end of thread, other threads:[~2004-10-29 19:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-10-29 18:37 PREPARE statement example error. Wood, Bruce <[email protected]>
2004-10-29 19:41 ` Tom Lane <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox