sqlalchemy not like
时间: 2023-10-18 20:30:41 浏览: 47
SQLAlchemy is a powerful SQL toolkit and Object-Relational Mapping (ORM) library for Python. It provides a way to work with databases using Python code rather than writing raw SQL queries. However, it doesn't have a direct "not like" operator like some SQL dialects do.
In SQLAlchemy, you can achieve the equivalent of a `not like` operation using the `not_()` function in conjunction with the `like()` function. Here's an example:
```python
from sqlalchemy import not_, like
query = session.query(MyTable).filter(not_(MyTable.column_name.like('%pattern%')))
```
In this code snippet, `MyTable` refers to the table you want to query, and `column_name` is the column you want to apply the `not like` condition on. `%pattern%` is the pattern you want to exclude from the results.
This construct will generate a SQL query that resembles `... WHERE column_name NOT LIKE '%pattern%'`.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)