Release: 1.4.0b1 pre release | Release Date: unreleased

SQLAlchemy 1.4 Documentation

SQLAlchemy 2.0 Future (Core)

See also

SQLAlchemy 2.0 Transition - Introduction to the 2.0 series of SQLAlchemy

sqlalchemy.future.select(*entities)

Construct a new Select using the 2.x style API.

New in version 2.0: - the future.select() construct is the same construct as the one returned by sql.expression.select(), except that the function only accepts the “columns clause” entities up front; the rest of the state of the SELECT should be built up using generative methods.

Similar functionality is also available via the FromClause.select() method on any FromClause.

See also

Selecting - Core Tutorial description of select().

Parameters

*entities

Entities to SELECT from. For Core usage, this is typically a series of ColumnElement and / or FromClause objects which will form the columns clause of the resulting statement. For those objects that are instances of FromClause (typically Table or Alias objects), the FromClause.c collection is extracted to form a collection of ColumnElement objects.

This parameter will also accept Text constructs as given, as well as ORM-mapped classes.

class sqlalchemy.future.Result(context)

Bases: sqlalchemy.sql.expression.Generative, sqlalchemy.engine.BaseResult

Interim “future” result proxy so that dialects can build on upcoming 2.0 patterns.

__eq__()

inherited from the __eq__() method of object

Return self==value.

__le__()

inherited from the __le__() method of object

Return self<=value.

__lt__()

inherited from the __lt__() method of object

Return self<value.

__ne__()

inherited from the __ne__() method of object

Return self!=value.

close()

Close this Result.

This closes out the underlying DBAPI cursor corresponding to the statement execution, if one is still present. Note that the DBAPI cursor is automatically released when the Result exhausts all available rows. Result.close() is generally an optional method except in the case when discarding a Result that still has additional rows pending for fetch.

After this method is called, it is no longer valid to call upon the fetch methods, which will raise a ResourceClosedError on subsequent use.

inserted_primary_key

inherited from the inserted_primary_key attribute of BaseResult

Return the primary key for the row just inserted.

The return value is a list of scalar values corresponding to the list of primary key columns in the target table.

This only applies to single row insert() constructs which did not explicitly specify Insert.returning().

Note that primary key columns which specify a server_default clause, or otherwise do not qualify as “autoincrement” columns (see the notes at Column), and were generated using the database-side default, will appear in this list as None unless the backend supports “returning” and the insert statement executed with the “implicit returning” enabled.

Raises InvalidRequestError if the executed statement is not a compiled expression construct or is not an insert() construct.

is_insert

inherited from the is_insert attribute of BaseResult

True if this ResultProxy is the result of a executing an expression language compiled expression.insert() construct.

When True, this implies that the inserted_primary_key attribute is accessible, assuming the statement did not include a user defined “returning” construct.

keys()

inherited from the keys() method of BaseResult

Return the list of string keys that would represented by each Row.

last_inserted_params()

inherited from the last_inserted_params() method of BaseResult

Return the collection of inserted parameters from this execution.

Raises InvalidRequestError if the executed statement is not a compiled expression construct or is not an insert() construct.

last_updated_params()

inherited from the last_updated_params() method of BaseResult

Return the collection of updated parameters from this execution.

Raises InvalidRequestError if the executed statement is not a compiled expression construct or is not an update() construct.

lastrow_has_defaults()

inherited from the lastrow_has_defaults() method of BaseResult

Return lastrow_has_defaults() from the underlying ExecutionContext.

See ExecutionContext for details.

lastrowid

inherited from the lastrowid attribute of BaseResult

return the ‘lastrowid’ accessor on the DBAPI cursor.

This is a DBAPI specific method and is only functional for those backends which support it, for statements where it is appropriate. It’s behavior is not consistent across backends.

Usage of this method is normally unnecessary when using insert() expression constructs; the inserted_primary_key attribute provides a tuple of primary key values for a newly inserted row, regardless of database backend.

class memoized_attribute(fget, doc=None)

A read-only @property that is only evaluated once.

__eq__()

inherited from the __eq__() method of object

Return self==value.

__le__()

inherited from the __le__() method of object

Return self<=value.

__lt__()

inherited from the __lt__() method of object

Return self<value.

__ne__()

inherited from the __ne__() method of object

Return self!=value.

classmethod memoized_instancemethod(fn)

inherited from the memoized_instancemethod() method of HasMemoized

Decorate a method memoize its return value.

postfetch_cols()

inherited from the postfetch_cols() method of BaseResult

Return postfetch_cols() from the underlying ExecutionContext.

See ExecutionContext for details.

Raises InvalidRequestError if the executed statement is not a compiled expression construct or is not an insert() or update() construct.

prefetch_cols()

inherited from the prefetch_cols() method of BaseResult

Return prefetch_cols() from the underlying ExecutionContext.

See ExecutionContext for details.

Raises InvalidRequestError if the executed statement is not a compiled expression construct or is not an insert() or update() construct.

returned_defaults

inherited from the returned_defaults attribute of BaseResult

Return the values of default columns that were fetched using the ValuesBase.return_defaults() feature.

The value is an instance of Row, or None if ValuesBase.return_defaults() was not used or if the backend does not support RETURNING.

New in version 0.9.0.

returns_rows

inherited from the returns_rows attribute of BaseResult

True if this ResultProxy returns rows.

I.e. if it is legal to call the methods fetchone(), fetchmany() fetchall().

rowcount

inherited from the rowcount attribute of BaseResult

Return the ‘rowcount’ for this result.

The ‘rowcount’ reports the number of rows matched by the WHERE criterion of an UPDATE or DELETE statement.

Note

Notes regarding ResultProxy.rowcount:

  • This attribute returns the number of rows matched, which is not necessarily the same as the number of rows that were actually modified - an UPDATE statement, for example, may have no net change on a given row if the SET values given are the same as those present in the row already. Such a row would be matched but not modified. On backends that feature both styles, such as MySQL, rowcount is configured by default to return the match count in all cases.

  • ResultProxy.rowcount is only useful in conjunction with an UPDATE or DELETE statement. Contrary to what the Python DBAPI says, it does not return the number of rows available from the results of a SELECT statement as DBAPIs cannot support this functionality when rows are unbuffered.

  • ResultProxy.rowcount may not be fully implemented by all dialects. In particular, most DBAPIs do not support an aggregate rowcount result from an executemany call. The ResultProxy.supports_sane_rowcount() and ResultProxy.supports_sane_multi_rowcount() methods will report from the dialect if each usage is known to be supported.

  • Statements that use RETURNING may not return a correct rowcount.

supports_sane_multi_rowcount()

inherited from the supports_sane_multi_rowcount() method of BaseResult

Return supports_sane_multi_rowcount from the dialect.

See ResultProxy.rowcount for background.

supports_sane_rowcount()

inherited from the supports_sane_rowcount() method of BaseResult

Return supports_sane_rowcount from the dialect.

See ResultProxy.rowcount for background.

Previous: Core Internals Next: Dialects