There is DataFrame.to_sql method, but it works only for mysql, sqlite and oracle databases. I cant pass to this method postgres connection or sqlalchemy engine.
Tag: sqlalchemy
Does begin_nested() automatically rollback/commit?
When begin_nested is used as a context manager, e.g. with db.session.begin_nested: # do something If an IntegrityError is thrown, will db.session.rollbank() be called automatically? On the …
How do I write a group_concat function in sqlalchemy?
I am trying to re-write this mysql query in SQLAlchemy: Schema: Query: Here’s what I have, but I keep getting: Answer Defining a custom function element seems the easiest way to take care of the group_concat method. And use it something like this:
“set session” in a SQLAlchemy session object
I’m using SQLAlchemy for a project, and need to be able to specify a session variable/setting for one specific call for performance reasons: set session max_heap_table_size = 1024 * 1024 * 64; I can …
How to execute raw SQL in Flask-SQLAlchemy app
How do you execute raw SQL in SQLAlchemy? I have a python web app that runs on flask and interfaces to the database through SQLAlchemy. I need a way to run the raw SQL. The query involves multiple table joins along with Inline views. I’ve tried: But I keep getting gateway errors. Answer Have you tried: or: Note that db.engine.execute()
sqlalchemy generic foreign key (like in django ORM)
Does sqlalchemy have something like django’s GenericForeignKey? And is it right to use generic foreign fields. My problem is: I have several models (for example, Post, Project, Vacancy, nothing special there) and I want to add comments to each of them. And I want to use only one Comment model. Does it worth to? Or should I use PostComment, ProjectComment
AttributeError while querying: Neither ‘InstrumentedAttribute’ object nor ‘Comparator’ has an attribute
The following code: is giving me this error: Any explanations, as to why this is happening, and guidance to how such a thing could be achieved? Answer This is because you are trying to access bar from the FooBar class rather than a FooBar instance. The FooBar class does not have any bar objects associated with it–bar is just an
sqlalchemy OperationalError: (OperationalError) (1045, “Access denied for user
I am trying to create a remote database using mysql on an Ubuntu machine running 12.04. It has a root user with remote login enabled.I have started the server. output of shows From the client machine that also runs Ubuntu 12.04 I use a python script to connect to the remote mysql database using sqlalchemy. The create_engine() call is failing
Altering an Enum field using Alembic
How can I add an element to an Enum field in an alembic migration when using a version of PostgreSQL older than 9.1 (which adds the ALTER TYPE for enums)? This SO question explains the direct process, …
SQLAlchemy ORM select multiple entities from subquery
I need to query multiple entities, something like session.query(Entity1, Entity2), only from a subquery rather than directly from the tables. The docs have something about selecting one entity from a …