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

pglast ignore database name during parsing #71

Closed
StpMax opened this issue Mar 4, 2021 · 4 comments
Closed

pglast ignore database name during parsing #71

StpMax opened this issue Mar 4, 2021 · 4 comments

Comments

@StpMax
Copy link

StpMax commented Mar 4, 2021

pglast version: v1.17

I get identical result for parsing this two queries:

>>> pprint(pglast.parse_sql('select 1 from b.a'))
[{'RawStmt': {'stmt': {'SelectStmt': {'fromClause': [{'RangeVar': {'inh': True,
                                                                   'location': 14,
                                                                   'relname': 'a',
                                                                   'relpersistence': 'p',
                                                                   'schemaname': 'b'}}],
                                      'op': 0,
                                      'targetList': [{'ResTarget': {'location': 7,
                                                                    'val': {'A_Const': {'location': 7,
                                                                                        'val': {'Integer': {'ival': 1}}}}}}]}}}}]
>>> pprint(pglast.parse_sql('select 1 from c.b.a'))
[{'RawStmt': {'stmt': {'SelectStmt': {'fromClause': [{'RangeVar': {'inh': True,
                                                                   'location': 14,
                                                                   'relname': 'a',
                                                                   'relpersistence': 'p',
                                                                   'schemaname': 'b'}}],
                                      'op': 0,
                                      'targetList': [{'ResTarget': {'location': 7,
                                                                    'val': {'A_Const': {'location': 7,
                                                                                        'val': {'Integer': {'ival': 1}}}}}}]}}}}]

For me, expected behaviour in second case is get error or get additional field in ['RangeVar']['catalogname'] = 'c'.

@lelit
Copy link
Owner

lelit commented Mar 4, 2021

Indeed, current stable underlying libpg_query does not emit the catalogname attribute, while upcoming does.

Maybe you could try to ask Lukas if this calls for an issue/PR?

@lelit
Copy link
Owner

lelit commented Mar 24, 2021

I will fix this, but only in v3.

@lelit
Copy link
Owner

lelit commented Mar 24, 2021

More precisely, v3 already emits that:

$ pgpp -tS "select 1 from c.b.a"
[{'@': 'RawStmt',
  'stmt': {'@': 'SelectStmt',
           'all': False,
           'fromClause': ({'@': 'RangeVar',
                           'catalogname': 'c',
                           'inh': True,
                           'location': 14,
                           'relname': 'a',
                           'relpersistence': 'p',
                           'schemaname': 'b'},),
           'limitOption': {'#': 'LimitOption',
                           'name': 'LIMIT_OPTION_DEFAULT',
                           'value': 0},
           'op': {'#': 'SetOperation', 'name': 'SETOP_NONE', 'value': 0},
           'targetList': ({'@': 'ResTarget',
                           'location': 7,
                           'val': {'@': 'A_Const',
                                   'location': 7,
                                   'val': {'@': 'Integer', 'val': 1}}},)},
  'stmt_len': 0,
  'stmt_location': 0}]

but it is currently ignored by the printer.
Out of curiosity, what's the meaning of that?

@lelit
Copy link
Owner

lelit commented May 3, 2021

This is fixed in v3.0dev0.

@lelit lelit closed this as completed May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants