Re: How to use the SQL parser subsystem

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: list(dot)jaju(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to use the SQL parser subsystem
Date: 2007-01-04 15:03:26
Message-ID: 20070105.000326.74752033.t-ishii@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Hi.
>
> Is it possible to use the SQL parser embedded inside the postgres code via
> some public API?
> I wish to get a parsed SQL query in any format which lends itself to easy
> analysis (structural, for example) so as to be able to find similarities
> between queries.
>
> I tried peeking around a bit, and tried pulling out src/backend/parser - but
> that depends on other parts of the code, making it a bit non-trivial. Plus,
> any changes in the base code upstream would not be available to this
> pulled-out application over time. Looking further, I noticed on my Fedora
> distribution that the pg devel package has a parser/parser.h file which
> exposes the function 'raw_parser' which is the function that seemed most
> interesting to me while exploring the code too.
>
> I have some questions:
> 1] is 'raw_parser' the right function to parse an SQL statement (for mainly
> structural/syntactic analysis)?

Yes.

> 2] If yes, I found that none of the shared library files expose this
> function - I could not link a simple C program with this function
> successfully. (I tried all the .so files related to postgres! :-()

It's not exported.

> 3] If not, what would be a better mechanism to re-use all the work already
> done in postgres for SQL analysis?

One idea would be writing a PostgreSQL function which calls
raw_parser() and returns the parse tree as a texual representaion.

Another idea would be pulling out raw_parser() along with related
functions from PostgreSQL. pgpool-II
(http://pgfoundry.org/projects/pgpool/) has alread done this.
--
Tatsuo Ishii
SRA OSS, Inc. Japan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karsten Hilbert 2007-01-04 15:18:56 self-referential UPDATE problem on 7.4
Previous Message Ravindra Jaju 2007-01-04 15:03:25 Re: How to use the SQL parser subsystem