Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
SQLAlchemy - Cómo negar una expresión ANY

Estoy usando postgres y estoy tratando de obtener esta consulta sin procesar usando la expresión SQLAlchemy, pero no puedo:

 SELECT foo.id FROM foo WHERE NOT foo.id = ANY('{1,2,3}'::int[]);

Lo probé con la siguiente definición de tabla:

 from sqlalchemy import Column, Integer, String from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class foo(Base): __tablename__ = 'foo' id = Column(Integer(), primary_key=True) name = Column(String(80), unique=True)

y ejecutando lo siguiente en IPython :

 In [57]: from sqlalchemy.sql.expression import any_, not_ In [58]: from sqlalchemy.dialects import postgresql In [59]: def compile_(where): ...: statement = select([foo.id, foo.name]).where(where) ...: return str(statement.compile(dialect=postgresql.dialect())) ...: In [60]: where1 = not_(foo.id == any_([1,2,3])) In [61]: compile_(where1) Out[61]: 'SELECT foo.id, foo.name \nFROM foo \nWHERE foo.id != ANY (%(param_1)s)'

Como puede ver, en lugar de obtener WHERE NOT foo.id != ANY(...) obtengo WHERE foo.id != ANY(...) .

NOTAS :

Conozco IN y NOT IN , pero no puedo usarlos debido a la longitud de other que es > 32767 y esto provoca un Error de InterfaceError debido a la cantidad de argumentos de enlace.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Parece que SQLAlchemy intenta ser demasiado inteligente. Puede ser más astuto que no usando NOT :

 where1 = foo.id != all_([1,2,3]))
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!