Reputation: 110562
Is there a place that says what that documents the Postgres parse tree? For example from Query Parsing it gives an example of:
SELECT * FROM foo where bar = 42 ORDER BY id DESC LIMIT 23;
(
{SELECT
:distinctClause <>
:intoClause <>
:targetList (
{RESTARGET
:name <>
:indirection <>
:val
...
But I can't find a place that gives more information, for example, what is indirection
in the RESTARGET
clause? It does link to the Postgres internals docs @ https://www.postgresql.org/docs/current/overview.html, but I couldn't find anything about the Postgres parse tree in detail from that. Is anything documented on that?
Note: for the question I'm only concerned with the SELECT
statement.
Upvotes: 1
Views: 356
Reputation: 371
Most of the relevant structs are defined in parsenodes.h, e.g. ResTarget and its attributes are defined here:
https://github.com/postgres/postgres/blob/master/src/include/nodes/parsenodes.h#L461
You may also find pg_query useful, a library I wrote to parse queries using the Postgres parser: https://github.com/pganalyze/pg_query (the output format is either JSON or Protobuf, and maps to the parsenodes.h struct names 1:1)
Upvotes: 1