sqlalchemy

Strings used in query always sent with NVARCHAR syntax, even if the underlying column is not unicode

谁说胖子不能爱 提交于 2021-01-27 22:19:03
问题 I'm noticing some odd behavior in the SQL generated for queries against string fields in MS SQL. Server version: SQL Server 2014 12.0.5000.0 Collation: SQL_Latin1_General_CP1_CI_AS Python version: 3.7 Our database has a mix of NVARCHAR (mostly newer) and VARCHAR (mostly older) fields. We are using SQLAlchemy to connect our Python application to the database, and even though we specify that a column is of type String (as opposed to Unicode ), the executed SQL always comes out in NVARCHAR

'Multi' method is not allowed when loading data to Oracle database with sqlalchemy

China☆狼群 提交于 2021-01-27 19:26:59
问题 I am using sqlalchemy and pandas to load dataframe to Oracle database. Since 'multi'method allows to upload in bulk, I choose that method. My pandas version is 1.0.1. However I got the error as following: The 'oracle' dialect with current database version settings does not support in-place multirow inserts. from sqlalchemy import create_engine oracle_connection_string = ( 'oracle+cx_oracle://{username}:{password}@' + cx_Oracle.makedsn('{hostname}', '{port}', service_name='{service_name}'))

How to use an existing sqlalchemy Enum in an Alembic migration (Postgres)

懵懂的女人 提交于 2021-01-27 13:00:53
问题 At some point in the past I've run an alembic migration which creates a users table like... def upgrade(): ... op.create_table( "users", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), ... sa.Column("type", sa.Enum("Foo", "Bar", "Baz", name="usertype"), nullable=False), ... ) ... ...which automatically creates the enum named usertype with the values "Foo", "Bar", "Baz" . Now, I want to make some other table which also references that same enum. e.g., def upgrade(): ... op

psycopg2 register_composite from sqlalchemy

纵然是瞬间 提交于 2021-01-27 12:56:58
问题 is it possible to somehow use function register_composite from psycopg2, when i am using sqlalchemy to connect to postgresql database? My problem is that I want SQLAlchemy to handle custom composite type that i created in postgresql like this: CREATE TYPE card AS (value int, suit text); Sqlalchemy returns me values of this type as an string and I would like to somhow learn sqlalchemy my new type. If found some information about creating custom composite types in SQL alchemy ORM, but I am

How to compare dates in sqlalchemy?

戏子无情 提交于 2021-01-27 11:56:04
问题 I have the following simple setup, where fromDate and toDate are strings on the format "YYYY-MM-DD": class SomeType(Base): date = Column(DateTime) def findAll(fromDate, toDate): return session.query(SomeType).filter(SomeType.date >= fromDate, SomeType.date <= toDate).all() The problem is that it doesn't find what I want it to find unless I modify the input dates like this: def findAll(fromDate, toDate): fromDate = fromDate + " 00:00" toDate = toDate + " 24:00" return session.query(SomeType)

PyCharm warns about unexpected arguments for SQLAlchemy User model

浪子不回头ぞ 提交于 2021-01-27 06:46:52
问题 I'm working with Flask-SQLAlchemy in PyCharm. When I try to create instances of my User model by passing keyword arguments to the model, PyCharm highlights the arguments with an "Unexpected argument(s)" warning. When I create instances of other models, I don't get this warning. Why am I getting this error for my User model? class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String, unique=True, nullable=False) new_user = User(username="test")

PyCharm warns about unexpected arguments for SQLAlchemy User model

会有一股神秘感。 提交于 2021-01-27 06:43:39
问题 I'm working with Flask-SQLAlchemy in PyCharm. When I try to create instances of my User model by passing keyword arguments to the model, PyCharm highlights the arguments with an "Unexpected argument(s)" warning. When I create instances of other models, I don't get this warning. Why am I getting this error for my User model? class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String, unique=True, nullable=False) new_user = User(username="test")

SQLAlchemy inheritance filter on all columns

断了今生、忘了曾经 提交于 2021-01-27 06:35:14
问题 So I want to execute a filter on all Columns of my Database Model which uses table inheritance. I am by no means sure if this is actually do-able or not. To get started let's use the same inheritance example from the SQLAlchemy Doc just slightly modified. I've omitted the imports here. class Employee(Base): __tablename__ = 'employee' id = Column(Integer, primary_key=True) name = Column(String(50)) type = Column(String(50)) __mapper_args__ = { 'polymorphic_identity':'employee', 'polymorphic_on

slqlalchemy UniqueConstraint VS Index(unique=True)

馋奶兔 提交于 2021-01-27 05:36:12
问题 I am using MySQL (running InnoDB), and wrapped the entire thing using sqlalchemy. Now, I would like to generate changes in my database by using (see docs) sqlalchemy_utils.functions.create_database(...) Generally the above function does what it is supposed to. The only exception being the generation of unique indexes. Say, I define a table like this: ## ... # DeclBase = declarative_base() ## ... class MyTable(DeclBase): __tablename__ = 'my_table' id = Column(Integer, primary_key=True) attr_1

How to store datetime with millisecond precision in SQL database

时间秒杀一切 提交于 2021-01-27 05:34:34
问题 With a float value representing date and time with millisecond precision: import datetime float_time = 1485538757.29289 print datetime.datetime.fromtimestamp(float_time) prints: 2017-01-27 09:39:17.292890 To store it in db: from sqlalchemy import Column, DateTime from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class MyTable(Base): __tablename__ = 'mytable' time_created = Column(DateTime, nullable=False) But saved value is rounded down to 2017-01-27 09:39:17