Home > Archive > PostgreSQL JDBC > January 2006 > cannot dollar-quote $$?$$ in PreparedStatements









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cannot dollar-quote $$?$$ in PreparedStatements
Marc Herbert

2006-01-11, 7:24 am


With 8.0 postgresql and driver, this works fine:
ps = con.prepareStatement("insert into product values(?, '?' , ?)");

But this fails:
ps = con.prepareStatement("insert into product values(?, $$?$$ , ?)");

It looks like "someone" (driver or engine?) is counting 3 parameters instead of 3:

org.postgresql.util.PSQLException: Pas de valeur specifiee pour le parametre 3.
at org.postgresql.core.v3.SimpleParameterList. checkAllParametersSe
t(SimpleParameterLis
t.java:102)
at org.postgresql.core.v3.QueryExecutorImpl. execute(QueryExecuto
rImpl.java:166)
at org.postgresql.jdbc2. AbstractJdbc2Stateme
nt. execute(AbstractJdbc
2Statement.java:389)
at org.postgresql.jdbc2. AbstractJdbc2Stateme
nt. executeWithFlags(Abs
tractJdbc2Statement.java:330)
at org.postgresql.jdbc2. AbstractJdbc2Stateme
nt. executeUpdate(Abstra
ctJdbc2Statement.java:282)
at TestFetchSize.main(TestFetchSize.java:86)


How dollar-quoting and question marks are supposed to interact?
Sorry if this a well-known issue.



---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Kris Jurka

2006-01-11, 11:24 am



On Wed, 11 Jan 2006, Marc Herbert wrote:

>
> With 8.0 postgresql and driver, this works fine:
> ps = con.prepareStatement("insert into product values(?, '?' , ?)");
>
> But this fails:
> ps = con.prepareStatement("insert into product values(?, $$?$$ , ?)");
>
> It looks like "someone" (driver or engine?) is counting 3 parameters
> instead of 3:
>


This is a known issue. The driver has no knowledge of dollar quotes in
its query parser. This is not just a problem for parameters, but also an
issue when people want to issue a create function command with
Statement.execute("CREATE FUNCTION f() RETURNS int AS $$ [a number of
statements separated by semicolons] $$ language plpgsql"); The driver
will detect the semicolons and try to execute each fragment separately.
So this is a know issue with the only workaround being to not use dollar
quotes.

Kris Jurka


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com