Error when printing exclusion constraint with operator explicitly specifying schema
Closed this issue · 4 comments
bennieswart commented
Consider the following code:
import pglast
sql = "ALTER TABLE T ADD CONSTRAINT C EXCLUDE USING gist (F WITH OPERATOR(intarray.&&))"
print(pglast.prettify(sql))
which produces the following error:
Traceback (most recent call last):
File "format.py", line 3, in <module>
print(pglast.prettify(sql))
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/__init__.py", line 46, in prettify
prettified = IndentedStream(**options)(Node(orig_pt))
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printer.py", line 251, in __call__
self.print_node(statement)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printer.py", line 380, in print_node
printer(node, self)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printers/dml.py", line 701, in raw_stmt
output.print_node(node.stmt)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printer.py", line 380, in print_node
printer(node, self)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printers/ddl.py", line 252, in alter_table_stmt
output.print_list(node.cmds, ',', standalone_items=True)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printer.py", line 598, in print_list
super().print_list(nodes, sep, relative_indent, standalone_items, are_names, is_symbol)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printer.py", line 437, in print_list
is_symbol=is_symbol)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printer.py", line 401, in _print_items
self.print_node(item, is_name=are_names, is_symbol=is_symbol and idx == last)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printer.py", line 380, in print_node
printer(node, self)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printers/ddl.py", line 284, in alter_table_cmd
output.print_node(constraint)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printer.py", line 380, in print_node
printer(node, self)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/printers/ddl.py", line 488, in constraint
output.write(clauses.string_value)
File "~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/pglast/node.py", line 143, in string_value
raise TypeError('%r does not contain a single String node' % self)
TypeError: [2*{String}] does not contain a single String node
This is almost certainly due to the &&
operator explicitly specifying the schema, that is, intarray.&&
.
Version used is pglast 1.17 on python 3.5.2.
lelit commented
Thank you for the report, I can see the same problem in v3. I will try to address the problem as soon as possible, but only on the latter version.
lelit commented
As the fix was so simple, I changed my mind and applied it on v1 and merged in v3.
lelit commented
I released v1.18 with the fix.
bennieswart commented
Thanks, great job!