pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dmitry Tkach <dmitry@openratings.com>
To: Darin Ohashi <DOhashi@maplesoft.com>
Cc: pgsql-jdbc-list <pgsql-jdbc@postgresql.org>
Subject: Re: Prepared Statements
Date: Fri, 18 Jul 2003 16:39:02 -0400
Message-ID: <3F185AE6.2@openratings.com> (raw)
In-Reply-To: <F17255C2B596D3119A5600508B44FA68052EB86A@courier.maplesoft.on.ca>
References: <F17255C2B596D3119A5600508B44FA68052EB86A@courier.maplesoft.on.ca>

Darin Ohashi wrote:

>The final SQL statement produced by a PS should be any valid SQL string, but a
>PS should not have to deal with being able to put that string together from
>arbitrary pieces of data. 
>
I agree with you on this one - not *arbitrary* pieces of data, no.

> I would be surprised if there was not a document
>somewhere that specified what is and is not valid to pass via a "?".
>  
>
If there is any, I've never heard of it...

>Looking at this particular example, it looks to me (of course, I have a limited
>amount of SQL experience) that "(1,2,3,4)" contains syntax.  Using (?,?,?,?) the
>"?" replace data and that should work.  As "(1,2,3,4)" contains syntax, I don't
>think it is a valid thing to substitute in.
>
Well... "(1,2,3,4)" *does* contain syntax. I agree on this one too.
*But*, (1,2,34)   itself is *not* just an arbitrary set of data, but a 
syntactical construct that represents a set.
I never said that using setObject (1, "(1,2,3,4,5)") is the ideal 
solution to my problem - it is just a workaround to the drivers 
inability to pass in a set any other way.
I would much prefer to use something like setObject (1, 
javaSetOfIntegers) if I could.
But we don't have it, and what I have now is better than nothing at all.

>
>Well, if you allow syntax to be substituted in to the PS, then the backend can't
>precompile because it does not have a syntatically complete statement.  What you
>substitute in could completely change the query optimization. 
>  
>
Sure. Even if you substitute just an int, it can very well change the 
optimal query plan
select ... where x=1 or select ... where x = 2000 could result in two 
totally different plans.
This is a known complication of precompiled statements.

One just has to know when it is better to precompile your queries and 
when it is not.

>  
>
>>>Do other JDBC drivers support this kind of substitution?
>>>
>>>      
>>>
>>Yes. They do (at least, the ones I worked with do).
>>    
>>
>
>Do they use actual precompiled statements or just with string concats?
>  
>
Yes, they do precompile the statements.

>  
>
>>No, that's not what I want...
>>What I want is an abstraction of the implementation-specific details, 
>>that lets me effectively execute sql queries.
>>If it can precompile my query, I want it to precompile it. If 
>>it cannot, 
>>I can live with that (for a while).
>>I just don't want to *know* what it is doing.
>>    
>>
>
>I accept that, but then you have to be willing to live by the rules of the spec,
>and I suspect this behaviour violates the spec.
>
>  
>
It doesn't violate it. I'll agree that it probably *extends* the spec... 
But I just don't think it is such a bad thing...


Dima




view thread (105+ messages)  latest in thread

Message-ID: <3F185AE6.2@openratings.com>
Permalink:  ../3F185AE6.2@openratings.com/
Also on:    postgresql.org/message-id/3F185AE6.2@openratings.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: dmitry@openratings.com, DOhashi@maplesoft.com
  Subject: Re: Prepared Statements
  In-Reply-To: <3F185AE6.2@openratings.com>
  References: <F17255C2B596D3119A5600508B44FA68052EB86A@courier.maplesoft.on.ca> <3F185AE6.2@openratings.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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