pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
cannot dollar-quote $$?$$ in PreparedStatements
2+ messages / 2 participants
[nested] [flat]

* cannot dollar-quote $$?$$ in PreparedStatements
@ 2006-01-11 11:41  Marc Herbert <Marc.Herbert@continuent.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Marc Herbert @ 2006-01-11 11:41 UTC (permalink / raw)
  To: pgsql-jdbc


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.checkAllParametersSet(SimpleParameterList.java:102)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:166)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:389)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:330)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.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.





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

* Re: cannot dollar-quote $$?$$ in PreparedStatements
@ 2006-01-11 16:58  Kris Jurka <books@ejurka.com>
  parent: Marc Herbert <Marc.Herbert@continuent.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Kris Jurka @ 2006-01-11 16:58 UTC (permalink / raw)
  To: Marc Herbert <Marc.Herbert@continuent.com>; +Cc: pgsql-jdbc



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




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


end of thread, other threads:[~2006-01-11 16:58 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-01-11 11:41 cannot dollar-quote $$?$$ in PreparedStatements Marc Herbert <Marc.Herbert@continuent.com>
2006-01-11 16:58 ` Kris Jurka <books@ejurka.com>

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