sqlalchemy

column_property (or other extra column) with window function?

拟墨画扇 提交于 2020-12-15 06:29:34
问题 I have the following situation, using SQLAlchemy with a MySQL database. Assume a Person table that looks like this: +------+-----------+----------+------------+ | ID | firstname | lastname | startdate | +------+-----------+----------+------------+ | 43 | Bob | Smith | 2016-12-04 | | 873 | Mary | Jones | 2018-05-01 | | 120 | Bob | Smith | 2020-04-02 | | 339 | Bob | Jones | 2019-03-01 | | 1022 | Bob | Smith | 2015-11-21 | +------+-----------+----------+------------+ I need to generate an extra

column_property (or other extra column) with window function?

送分小仙女□ 提交于 2020-12-15 06:27:29
问题 I have the following situation, using SQLAlchemy with a MySQL database. Assume a Person table that looks like this: +------+-----------+----------+------------+ | ID | firstname | lastname | startdate | +------+-----------+----------+------------+ | 43 | Bob | Smith | 2016-12-04 | | 873 | Mary | Jones | 2018-05-01 | | 120 | Bob | Smith | 2020-04-02 | | 339 | Bob | Jones | 2019-03-01 | | 1022 | Bob | Smith | 2015-11-21 | +------+-----------+----------+------------+ I need to generate an extra

How to use wild cards in SQLAlchemy? [duplicate]

和自甴很熟 提交于 2020-12-15 05:58:48
问题 This question already has an answer here : CS50: LIKE operator, variable substitution with % expansion (1 answer) Closed last year . I'm trying to use wildcards for a query using SQLAlchemy but I'm getting back an empty list. My code: engine = create_engine(os.getenv("DATABASE_URL")) db = scoped_session(sessionmaker(bind=engine)) s = input("Search for a book: ") q = db.execute(f"SELECT * FROM books WHERE isbn LIKE '%\:s\%' OR author LIKE '%\:s\%' OR title LIKE '%\:s\%'", {"s": s}).fetchall()

How to use wild cards in SQLAlchemy? [duplicate]

安稳与你 提交于 2020-12-15 05:58:21
问题 This question already has an answer here : CS50: LIKE operator, variable substitution with % expansion (1 answer) Closed last year . I'm trying to use wildcards for a query using SQLAlchemy but I'm getting back an empty list. My code: engine = create_engine(os.getenv("DATABASE_URL")) db = scoped_session(sessionmaker(bind=engine)) s = input("Search for a book: ") q = db.execute(f"SELECT * FROM books WHERE isbn LIKE '%\:s\%' OR author LIKE '%\:s\%' OR title LIKE '%\:s\%'", {"s": s}).fetchall()

What is this ZopeTransactionEvents error with SQLAlchemy while updating a Pyramid application?

南笙酒味 提交于 2020-12-15 05:30:27
问题 I'm updating Pyramid/SQLAlchemy legacy code to Python 3.8 from an app working fine under Python 2.7, and running it locally. All the necessary requirements are pip installed and setup.py runs without error. On running initialise with my local .ini file, All goes well, the database tables (MariaDB) are all written. in models.py from sqlalchemy.orm import ( scoped_session, sessionmaker, relationship, backref, synonym, ) from zope.sqlalchemy import ZopeTransactionEvents #[...] DBSession = scoped

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:bigquery

岁酱吖の 提交于 2020-12-13 18:04:06
问题 Trying to create a bigquery connector using sqlalchemy from sqlalchemy import create_engine engine = create_engine('bigquery://<project_id>/<project_name>', credentials_path=GCP_KEY) conn = engine.connect() Error: sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:bigquery 回答1: Your error is generally related to the lack of some required module to use SQLAlchemy. Therefore, after going though the documentation, I found out that you should install the requirements in you

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:bigquery

自作多情 提交于 2020-12-13 17:58:32
问题 Trying to create a bigquery connector using sqlalchemy from sqlalchemy import create_engine engine = create_engine('bigquery://<project_id>/<project_name>', credentials_path=GCP_KEY) conn = engine.connect() Error: sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:bigquery 回答1: Your error is generally related to the lack of some required module to use SQLAlchemy. Therefore, after going though the documentation, I found out that you should install the requirements in you

SQLAlchemy nearest datetime

泄露秘密 提交于 2020-12-13 03:59:35
问题 Is their any simple (fast) way to fetch a table and find the datetime nearest from a given dateTime in SQLAlchemy ? In most case the delta will be seconds between the datetime given and the one in the table. The date column is the primary key EDIT : I'm using SQLite 回答1: Since it is the primary key a simple "sort by diff ascending, fetch 1st row" might not be the fastest, though simple solution. A quick and dirty way could be to fetch a union of larger than and less than the given datetime,

SQLAlchemy nearest datetime

柔情痞子 提交于 2020-12-13 03:58:16
问题 Is their any simple (fast) way to fetch a table and find the datetime nearest from a given dateTime in SQLAlchemy ? In most case the delta will be seconds between the datetime given and the one in the table. The date column is the primary key EDIT : I'm using SQLite 回答1: Since it is the primary key a simple "sort by diff ascending, fetch 1st row" might not be the fastest, though simple solution. A quick and dirty way could be to fetch a union of larger than and less than the given datetime,

SQLAlchemy nearest datetime

可紊 提交于 2020-12-13 03:57:58
问题 Is their any simple (fast) way to fetch a table and find the datetime nearest from a given dateTime in SQLAlchemy ? In most case the delta will be seconds between the datetime given and the one in the table. The date column is the primary key EDIT : I'm using SQLite 回答1: Since it is the primary key a simple "sort by diff ascending, fetch 1st row" might not be the fastest, though simple solution. A quick and dirty way could be to fetch a union of larger than and less than the given datetime,