Parsed Query Trees

Поиск
Список
Период
Сортировка
Искать

Parsed Query Trees

От:
Kevin Neufeld <kneufeld@refractions.net>
Дата:
Does anyone know if a parsed query tree object is exposed in the jdbc 
API?  I couldn't find any such thing, nor could I find it in the 
developers roadmap.

My particular requirement is that I need to be able to parse / 
deconstruct an arbitrary SELECT query (which may be overly complicated) 
and add custom filters to the WHERE clause depending on what columns 
(optionally schema-qualified) and server datatypes are specified in the 
select clause.

I'm currently use a sql parser that I wrote, but it seems silly to have 
to re-invent the wheel.  I suppose I could use a 3rd party jar, like 
sql4j or Zsql, but these are rather old and simplistic and don't seem to 
do what I need them to do.  Postgres is already parsing my sql queries - 
it would just be nice to have access to these parsed query trees so I 
can edit and then resend them to the database.

Cheers,
Kevin

-------------
Kevin Neufeld
Software Developer
Refractions Research Inc.
300-1207 Douglas St.
Victoria, B.C., V8W 2E7

Phone: (250) 383-3022
Email: kneufeld@refractions.net

Re: Parsed Query Trees

От:
Oliver Jowett <oliver@opencloud.com>
Дата:
Kevin Neufeld wrote:
> Does anyone know if a parsed query tree object is exposed in the jdbc 
> API?  I couldn't find any such thing, nor could I find it in the 
> developers roadmap.

No, and the reason is that the JDBC driver doesn't actually parse the 
query beyond some basic manipulations to find parameter placeholders and 
so on. All the real parsing happens on the server side, and I don't know 
of a way to get access to the server's query tree as a client. (It's 
debatable how useful that would be, anyway)

-O

Re: Parsed Query Trees

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Oliver Jowett  writes:
> Kevin Neufeld wrote:
>> Does anyone know if a parsed query tree object is exposed in the jdbc 
>> API?  I couldn't find any such thing, nor could I find it in the 
>> developers roadmap.

> No, and the reason is that the JDBC driver doesn't actually parse the 
> query beyond some basic manipulations to find parameter placeholders and 
> so on. All the real parsing happens on the server side, and I don't know 
> of a way to get access to the server's query tree as a client. (It's 
> debatable how useful that would be, anyway)

I'd very strongly resist exposing the server's parsetrees to clients,
because then changing them would represent a protocol break, and we
change them constantly.

If you're desperate to have an editing facility like this, put it into
server-side code ... and expect to revise it at every major release.

			regards, tom lane

Re: Parsed Query Trees

От:
Kevin Neufeld <kneufeld@refractions.net>
Дата:
Hmmm. 
Thanx guys.  I didn't clue in that the parsetrees underwent constant 
change - they obviously do since query syntax changes all the time.  I'm 
clearly going to have to approach my problem from a different angle.

Cheers,
Kevin

Tom Lane wrote:
> Oliver Jowett  writes:
>   
>> Kevin Neufeld wrote:
>>     
>>> Does anyone know if a parsed query tree object is exposed in the jdbc 
>>> API?  I couldn't find any such thing, nor could I find it in the 
>>> developers roadmap.
>>>       
>
>   
>> No, and the reason is that the JDBC driver doesn't actually parse the 
>> query beyond some basic manipulations to find parameter placeholders and 
>> so on. All the real parsing happens on the server side, and I don't know 
>> of a way to get access to the server's query tree as a client. (It's 
>> debatable how useful that would be, anyway)
>>     
>
> I'd very strongly resist exposing the server's parsetrees to clients,
> because then changing them would represent a protocol break, and we
> change them constantly.
>
> If you're desperate to have an editing facility like this, put it into
> server-side code ... and expect to revise it at every major release.
>
> 			regards, tom lane
>   
FAQ