pglast ignore database name during parsing
StpMax opened this issue · 4 comments
StpMax commented
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 commented
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 commented
I will fix this, but only in v3.
lelit commented
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 commented
This is fixed in v3.0dev0.