Skip to content
Advertisement

how flask-sqlalchemy turn off returning id while insert data

I’m trying to insert data to PostgreSQL 8.3.23 by Flask-SQLAlchemy==2.3.2, the errors show that INSERT statement is not supported in this version of Greenplum Database. so how can I turn off returning id in (flask-)sqlalchemy while insert.

JavaScript
JavaScript

Thanks in advance

Advertisement

Answer

You need to set the implicit_returning create_engine parameter to False.

JavaScript

When True, a RETURNING- compatible construct, if available, will be used to fetch newly generated primary key values when a single row INSERT statement is emitted with no existing returning() clause. This applies to those backends which support RETURNING or a compatible construct, including PostgreSQL, Firebird, Oracle, Microsoft SQL Server. Set this to False to disable the automatic usage of RETURNING.

Since version 2.4 Flask-SQLAlchemy provides a SQLALCHEMY_ENGINE_OPTIONS configuration option to pass a dictionary of keyword arguments for engine creation, so you can do

JavaScript

The following section applies to Flask-SQLAlchemy < 2.4, which had not been released when this answer was originally composed

Flask-SQLAlchemy doesn’t expose engine creation directly, it might be possible to override SQLAlchemy.apply_driver_hacks to inject the extra parameter.

This method is called before engine creation and used to inject driver specific hacks into the options. The options parameter is a dictionary of keyword arguments that will then be used to call the sqlalchemy.create_engine() function.

There is an outstanding pull-request to expose a simpler way to do this.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement