The precedence for EXISTS is lower than that of neg in sql/operators.py so it will always render the parenthesis unless those precedences are changed. otherwise you can use op() or whatever, ~op("EXISTS")("foo")
from sqlalchemy import select, column, Boolean from sqlalchemy.sql.expression import UnaryExpression from sqlalchemy.sql import operators unary = UnaryExpression(select([column('q')]), operator=operators.custom_op("EXISTS", precedence=10), type_=Boolean) print(~unary) On Wed, Mar 20, 2019 at 12:12 PM Jonathan Vanasco <jvana...@gmail.com> wrote: > > Is it possible to easily render "NOT EXISTS( " with a current API command? > > Both `~exists(` and `not_(exists(` will render "NOT ( EXISTS( ". I need to > remove the superfluous parenthesis (this has to do with unit tests and > ensuring parity of SQL across a handful of apps and custom commands). > > I could do this with a custom function or compiler, but I feel like I must be > missing something in the docs. > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.