1

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.

3
  • 2
    Most likely this is documented inside the source code. Commented Dec 11, 2021 at 10:45
  • Also, this can change from version to version. Commented Dec 12, 2021 at 4:43
  • @a_horse_with_no_name sure could you share the file(s) then where this is documented? Maybe even an answer with an example of where/how to find what indirection means? Commented Dec 12, 2021 at 18:31

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.