[PYTHON] Difference between SQLAlchemy filter () and filter_by ()

I will explain the difference because there are two functions, filter () and filter_by (), when searching the DB with SQLAlchemy, which is one of Python's O / R Mapper.

It was obvious when I looked at the official documentation. filter_by(),filter() In conclusion, fileter_by () seems to have the advantage of shorter code.

filter (): {model}. {variable name} can add table column value to search condition filter_by (): Column value can be added to the search condition only with {variable name} without model

It is easy to understand if you look at the code, so if you specify it

# filter()Description example when using
session.query(MyClass).\
    filter(MyClass.name == 'some name', MyClass.id > 5)

# filter_by()Description example when using
session.query(MyClass).\
    filter_by(name = 'some name', id > 5)

Personally, fileter_by can be written shorter, so I thought it would be convenient.

If anyone knows how to use filter (), which is useful when saying this, I would be grateful if you could let me know in the comments.

Recommended Posts

Difference between SQLAlchemy filter () and filter_by ()
Difference between SQLAlchemy flush () and commit ()
Difference between process and job
Difference between "categorical_crossentropy" and "sparse_categorical_crossentropy"
Difference between regression and classification
Difference between np.array and np.arange
Difference between MicroPython and CPython
Difference between ps a and ps -a
Difference between return and print-Python
Difference between Ruby and Python split
Difference between java and python (memo)
Difference between == and is in python
Memorandum (difference between csv.reader and csv.dictreader)
(Note) Difference between gateway and default gateway
Difference between Numpy randint and Random randint
Difference between sort and sorted (memorial)
Difference between python2 series and python3 series dict.keys ()
Difference between SQLAlchemy back_populates and backref and when neither is used
[Python] Difference between function and method
Python --Difference between exec and eval
[Python] Difference between randrange () and randint ()
[Python] Difference between sorted and sorted (Colaboratory)
[Xg boost] Difference between softmax and softprob
difference between statements (statements) and expressions (expressions) in Python
[Django ORM] Difference between values () and only ()
Difference between PHP and Python finally and exit
Difference between @classmethod and @staticmethod in Python
Difference between append and + = in Python list
Difference between nonlocal and global in Python
Difference between linear regression, Ridge regression and Lasso regression
[Python] Difference between class method and static method
Difference between docker-compose env_file and .env file
[Python Iroha] Difference between List and Tuple
[python] Difference between rand and randn output
speed difference between wsgi, Bottle and Flask
Difference between numpy.ndarray and list (dimension, size)
Difference between ls -l and cat command
Difference and compatibility verification between keras and tf.keras # 1
What is the difference between `pip` and` conda`?
Difference between using and import on shield language
[python] Difference between variables and self. Variables in class
About the difference between "==" and "is" in python
About the difference between PostgreSQL su and sudo
What is the difference between Unix and Linux?
Consideration of the difference between ROC curve and PR curve
The rough difference between Unicode and UTF-8 (and their friends)
Center difference and forward difference
Can BERT tell the difference between "candy (candy)" and "candy (rain)"?
Between parametric and nonparametric
Difference between Ruby and Python in terms of variables
What is the difference between usleep, nanosleep and clock_nanosleep?
Use SQLAlchemy and multiprocessing
Difference between Numpy (n,) and (n, 1) notation [Difference between horizontal vector and vertical vector]
Difference between return, return None, and no return description in Python
How to use argparse and the difference between optparse
What is the difference between a symbolic link and a hard link?
Python module num2words Difference in behavior between English and Russian
Python> Difference between inpbt and print (inpbt) output> [1. 2. 3.] / array ([1., 2., 3.], dtype = float32)
Understand the difference between cumulative assignment to variables and cumulative assignment to objects
List concatenation method in python, difference between list.extend () and “+” operator
The difference between foreground and background processes understood by the principle