Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass a not like operator in a sqlalchemy ORM query

I've got a query:

MyModel.query.filter(Mymodel.name.contains('a_string')) 

I need to do the same query but with the negation (a not like operator) but didn't find any operator matching my need in the SQLAlchemy documentation.

Is there any way to do it without using the sql part of SQLAlchemy???

like image 715
Jérôme Pigeot Avatar asked Feb 16 '11 15:02

Jérôme Pigeot


People also ask

What does all () do in SQLAlchemy?

all() method. The Query object, when asked to return full entities, will deduplicate entries based on primary key, meaning if the same primary key value would appear in the results more than once, only one object of that primary key would be present.

What is lazy true in SQLAlchemy?

Lazy parameter determines how the related objects get loaded when querying through relationships. Below listed are the four main lazy parameters. Typically when you query the database, the data get loaded at once; however, lazy parameter allows you to alternate the way they get loaded. lazy = 'select' (or True)

How do I select in SQLAlchemy?

The select() method of table object enables us to construct SELECT expression. The resultant variable is an equivalent of cursor in DBAPI. We can now fetch records using fetchone() method. Here, we have to note that select object can also be obtained by select() function in sqlalchemy.


1 Answers

Just negate the filter:

MyModel.query.filter(sqlalchemy.not_(Mymodel.name.contains('a_string'))) 
like image 99
Maxim Sloyko Avatar answered Sep 17 '22 23:09

Maxim Sloyko