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

Boolean clause WHERE ... IS TRUE raises error #11

Closed
maxalbert opened this issue Feb 12, 2019 · 4 comments
Closed

Boolean clause WHERE ... IS TRUE raises error #11

maxalbert opened this issue Feb 12, 2019 · 4 comments

Comments

@maxalbert
Copy link

maxalbert commented Feb 12, 2019

Here is a minimal example to reproduce (with pglast version 1.1).

from pglast import prettify

sql = "SELECT * FROM tbl WHERE foo IS TRUE"
prettify(sql)

Note that if we replace WHERE foo IS TRUE with WHERE foo = TRUE the error goes away.

Traceback:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/printer.py in get_printer_for_node_tag(parent_node_tag, node_tag)
     38     try:
---> 39         return NODE_PRINTERS[(parent_node_tag, node_tag)]
     40     except KeyError:

KeyError: ('SelectStmt', 'BooleanTest')

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/printer.py in get_printer_for_node_tag(parent_node_tag, node_tag)
     41         try:
---> 42             return NODE_PRINTERS[node_tag]
     43         except KeyError:

KeyError: 'BooleanTest'

During handling of the above exception, another exception occurred:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-2-2b516e62760f> in <module>
      2 
      3 sql = "SELECT * FROM tbl WHERE foo IS TRUE"
----> 4 prettify(sql)

~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/__init__.py in prettify(statement, safety_belt, **options)
     37 
     38     orig_pt = parse_sql(statement)
---> 39     prettified = IndentedStream(**options)(Node(orig_pt))
     40     if safety_belt:
     41         try:

~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/printer.py in __call__(self, sql, plpgsql)
    225                 if self.separate_statements:
    226                     self.newline()
--> 227             self.print_node(statement)
    228         return self.getvalue()
    229 

~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/printer.py in print_node(self, node, is_name, is_symbol)
    350                 printer(node, self, is_name=is_name, is_symbol=is_symbol)
    351             else:
--> 352                 printer(node, self)
    353         self.separator()
    354 

~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/printers/dml.py in raw_stmt(node, output)
    613 @node_printer('RawStmt')
    614 def raw_stmt(node, output):
--> 615     output.print_node(node.stmt)
    616 
    617 

~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/printer.py in print_node(self, node, is_name, is_symbol)
    350                 printer(node, self, is_name=is_name, is_symbol=is_symbol)
    351             else:
--> 352                 printer(node, self)
    353         self.separator()
    354 

~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/printers/dml.py in select_stmt(node, output)
    689                 output.newline()
    690                 output.write('WHERE ')
--> 691                 output.print_node(node.whereClause)
    692             if node.groupClause:
    693                 output.newline()

~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/printer.py in print_node(self, node, is_name, is_symbol)
    346         else:
    347             parent_node_tag = node.parent_node and node.parent_node.node_tag
--> 348             printer = get_printer_for_node_tag(parent_node_tag, node.node_tag)
    349             if is_name and node.node_tag == 'String':
    350                 printer(node, self, is_name=is_name, is_symbol=is_symbol)

~/.local/share/virtualenvs/flowmachine-k9pemXkM/lib/python3.7/site-packages/pglast/printer.py in get_printer_for_node_tag(parent_node_tag, node_tag)
     43         except KeyError:
     44             raise NotImplementedError("Printer for node %r is not implemented yet"
---> 45                                       % node_tag)
     46 
     47 

NotImplementedError: Printer for node 'BooleanTest' is not implemented yet
@lelit
Copy link
Owner

lelit commented Feb 13, 2019

Thank you for the report, will fix this shortly!

lelit added a commit that referenced this issue Feb 13, 2019
@lelit
Copy link
Owner

lelit commented Feb 13, 2019

This is fixed in just released version 1.2.

@lelit lelit closed this as completed Feb 13, 2019
@maxalbert
Copy link
Author

Brilliant, thanks so much for the super quick reply and the fix. 👏

@lelit
Copy link
Owner

lelit commented Feb 13, 2019

You're welcome!

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