diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-10-01 22:18:38 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-10-01 22:18:38 +0000 |
| commit | 82c359ae93fde8c12a562f3856e75631e9d6a5cf (patch) | |
| tree | 5a0a29270e8a3697348b36f36754204eb3755d06 /lib/sqlalchemy/sql | |
| parent | b230298234ea3a51c07538a37bee21d8ccb28303 (diff) | |
| parent | 42851df7707769bf0bf4db74108699e9f56c5fac (diff) | |
| download | sqlalchemy-82c359ae93fde8c12a562f3856e75631e9d6a5cf.tar.gz | |
Merge "Fixes: #4504"
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/elements.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 58db56a9c..04565443d 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -3272,6 +3272,36 @@ class Extract(ColumnElement): as well as ``func.extract`` from the :data:`.func` namespace. + :param field: The field to extract. + + :param expr: A column or Python scalar expression serving as the + right side of the ``EXTRACT`` expression. + + E.g.:: + + from sqlalchemy import extract + from sqlalchemy import table, column + + logged_table = table("user", + column("id"), + column("date_created"), + ) + + stmt = select(logged_table.c.id).where( + extract("YEAR", logged_table.c.date_created) == 2021 + ) + + In the above example, the statement is used to select ids from the + database where the ``YEAR`` component matches a specific value. + + Similarly, one can also select an extracted component:: + + stmt = select( + extract("YEAR", logged_table.c.date_created) + ).where(logged_table.c.id == 1) + + The implementation of ``EXTRACT`` may vary across database backends. + Users are reminded to consult their database documentation. """ self.type = type_api.INTEGERTYPE self.field = field |
