pg_query icon indicating copy to clipboard operation
pg_query copied to clipboard

Purpose of location value on node

Open kduraiswami opened this issue 2 years ago • 1 comments

I am working on a project that involves a lot of manipulation and adding to the original tree that comes into the service.

I am a little bit scared to try and handle all edge cases when I am inserting and moving nodes around so I am trying to use as much of the original tree as possible rather than error handling on every single attribute.

Is there any risk with having the “location” value out of order within an array or within a branch of a tree? Is there any risk of not having location declared on a node at all?

The deparse method does not seem to care, but want to make sure.

kduraiswami avatar Jul 08 '23 21:07 kduraiswami

You can leave the location field empty (causing it to be 0), or set it to -1 (which is what Postgres uses when the location is unknown).

The location doesn't matter at all for passing things into the deparser, so it shouldn't be needed for your use case.

Its originally intended to provide the user context of where an error in the query occurred (i.e. when parsing an error is hit), has some use in the pg_stat_statements normalization, and in pg_query some users make use of it when trying to figure out where in the source query a particular AST item is. But all of that doesn't matter for passing things into the deparser.

lfittl avatar Jul 10 '23 03:07 lfittl