-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I know this sounds kind of silly, but I think I would like to be able to 
send a query to PostgreSQL, and have it parse it into a tree, and then pass 
the tree back to me somehow. Of course, I don't want the query to actually 
execute.

Writing the front end application of materialized views, I would like to see 
if I can deduce what triggers to put where based on the parse tree a query 
returns.

Are there any tools to do this? Is this something that exists but is not 
documented? Perhaps we can add a "PARSE TREE <query>" command?

- -- 
Jonathan Gardner
jgardner@jonathangardner.net
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/xbNZWgwF3QvpWNwRAmFuAKDVLnj4/66MFHya7bGGeVTs5os0UwCeIcB7
HYzvgpkc8FCyWRAyh75mn3k=
=TVIM
-----END PGP SIGNATURE-----


Thu, 27 Nov 2003 00:18:33 -0800
Jonathan Gardner <jgardner@jonathangardner.net>
Viewing Parse Tree of a query from front end
Jonathan Gardner writes:

> I know this sounds kind of silly, but I think I would like to be able to
> send a query to PostgreSQL, and have it parse it into a tree, and then pass
> the tree back to me somehow. Of course, I don't want the query to actually
> execute.

There is a configuration parameter that make each statement print out the
parse tree.  I think it's show_parse_tree or something like that.

-- 
Peter Eisentraut   peter_e@gmx.net


Thu, 27 Nov 2003 10:12:46 +0100 (CET)
Peter Eisentraut <peter_e@gmx.net>
Re: Viewing Parse Tree of a query from front end
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 27 November 2003 1:12 am, Peter Eisentraut wrote:
> Jonathan Gardner writes:
> > I know this sounds kind of silly, but I think I would like to be able
> > to send a query to PostgreSQL, and have it parse it into a tree, and
> > then pass the tree back to me somehow. Of course, I don't want the
> > query to actually execute.
>
> There is a configuration parameter that make each statement print out the
> parse tree.  I think it's show_parse_tree or something like that.

I found it. Thanks for pointing out where it was.

=> SET client_min_messages=debug1;
=> SET debug_print_parse=on;
=> select * from test;
DEBUG:  parse tree:
DETAIL:  {QUERY :commandType 1 :querySource 0 :canSetTag true :utilityStmt 
<>
:resultRelation 0 :into <> :hasAggs false :hasSubLinks false :rtable ({RTE
:alias <> :eref {ALIAS :aliasname test :colnames ("id" "test")} :rtekind 0
:relid 17145 :inh true :inFromCl true :checkForRead true :checkForWrite 
false
:checkAsUser 0}) :jointree {FROMEXPR :fromlist ({RANGETBLREF :rtindex 1})
:quals <>} :rowMarks () :targetList ({TARGETENTRY :resdom {RESDOM :resno 1
:restype 23 :restypmod -1 :resname id :ressortgroupref 0 :resorigtbl 17145
:resorigcol 1 :resjunk false} :expr {VAR :varno 1 :varattno 1 :vartype 23
:vartypmod -1 :varlevelsup 0 :varnoold 1 :varoattno 1}} {TARGETENTRY :resdom
{RESDOM :resno 2 :restype 16 :restypmod -1 :resname test :ressortgroupref 0
:resorigtbl 17145 :resorigcol 2 :resjunk false} :expr {VAR :varno 1 
:varattno
2 :vartype 16 :vartypmod -1 :varlevelsup 0 :varnoold 1 :varoattno 2}})
:groupClause <> :havingQual <> :distinctClause <> :sortClause <> 
:limitOffset
<> :limitCount <> :setOperations <> :resultRelations ()}

(and the results follow)

This is seriously cool.

- -- 
Jonathan Gardner
jgardner@jonathangardner.net
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/xj3mWgwF3QvpWNwRAlCUAKClIhCEkeZZK7r29RHvEnkB8mIX7gCfeMlq
SeM7RD13b9qfhp8wAckZvXU=
=gKET
-----END PGP SIGNATURE-----


Thu, 27 Nov 2003 10:09:41 -0800
Jonathan Gardner <jgardner@jonathangardner.net>
Re: Viewing Parse Tree of a query from front end