Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purpose of location value on node #297

Open
kduraiswami opened this issue Jul 8, 2023 · 1 comment
Open

Purpose of location value on node #297

kduraiswami opened this issue Jul 8, 2023 · 1 comment
Labels

Comments

@kduraiswami
Copy link

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.

@lfittl
Copy link
Member

lfittl commented Jul 10, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants