class documentation

class Sequence(IdentityOptions, DefaultGenerator):

View In Hierarchy

Represents a named database sequence.

The .Sequence object represents the name and configurational parameters of a database sequence. It also represents a construct that can be "executed" by a SQLAlchemy _engine.Engine or _engine.Connection, rendering the appropriate "next value" function for the target database and returning a result.

The .Sequence is typically associated with a primary key column:

some_table = Table(
    'some_table', metadata,
    Column('id', Integer, Sequence('some_table_seq'),
    primary_key=True)
)

When CREATE TABLE is emitted for the above _schema.Table, if the target platform supports sequences, a CREATE SEQUENCE statement will be emitted as well. For platforms that don't support sequences, the .Sequence construct is ignored.

See Also

:ref:`defaults_sequences`

.CreateSequence

.DropSequence

Method __init__ Construct a .Sequence object.
Method ​_not​_a​_column​_expr Undocumented
Method ​_set​_metadata Undocumented
Method ​_set​_parent Associate with this SchemaEvent's parent object.
Method ​_set​_table Undocumented
Method create Creates this sequence in the database.
Method drop Drops this sequence from the database.
Method next​_value Return a .next_value function element which will render the appropriate increment function for this .Sequence within any SQL expression.
Class Variable __visit​_name__ Undocumented
Class Variable is​_sequence Undocumented
Instance Variable ​_key Undocumented
Instance Variable data​_type Undocumented
Instance Variable metadata Undocumented
Instance Variable name Undocumented
Instance Variable optional Undocumented
Instance Variable schema Undocumented
Property bind Return the connectable associated with this default.
Property is​_callable Undocumented
Property is​_clause​_element Undocumented

Inherited from IdentityOptions:

Instance Variable cache Undocumented
Instance Variable cycle Undocumented
Instance Variable increment Undocumented
Instance Variable maxvalue Undocumented
Instance Variable minvalue Undocumented
Instance Variable nomaxvalue Undocumented
Instance Variable nominvalue Undocumented
Instance Variable order Undocumented
Instance Variable start Undocumented

Inherited from DefaultGenerator:

Method ​_execute​_on​_connection Undocumented
Method execute Compile and execute this .Executable.
Class Variable is​_server​_default Undocumented
Instance Variable column Undocumented
Instance Variable for​_update Undocumented

Inherited from Executable (via DefaultGenerator):

Method ​_add​_context​_option Add a context option to this statement.
Method ​_set​_compile​_options Assign the compile options to a new value.
Method ​_update​_compile​_options update the _compile_options with new keys.
Method execution​_options Set non-SQL options for the statement which take effect during execution.
Method get​_execution​_options Get the non-SQL options which will take effect during execution.
Method options Apply options to this statement.
Method scalar Compile and execute this .Executable, returning the result's scalar representation.
Class Variable ​_bind Undocumented
Class Variable ​_executable​_traverse​_internals Undocumented
Class Variable ​_with​_context​_options Undocumented
Class Variable ​_with​_options Undocumented
Class Variable is​_delete Undocumented
Class Variable is​_dml Undocumented
Class Variable is​_insert Undocumented
Class Variable is​_select Undocumented
Class Variable is​_text Undocumented
Class Variable is​_update Undocumented
Class Variable supports​_execution Undocumented
Instance Variable ​_compile​_options Undocumented
Instance Variable ​_execution​_options Undocumented
Property ​_effective​_plugin​_target Undocumented

Inherited from StatementRole (via DefaultGenerator, Executable):

Class Variable ​_propagate​_attrs Undocumented
Class Variable ​_role​_name Undocumented

Inherited from SQLRole (via DefaultGenerator, Executable, StatementRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from Generative (via DefaultGenerator, Executable):

Method ​_generate Undocumented

Inherited from SchemaItem (via DefaultGenerator):

Method __repr__ Undocumented
Method ​_init​_items Initialize the list of child items for this SchemaItem.
Method ​_schema​_item​_copy Undocumented
Class Variable ​_use​_schema​_map Undocumented
Class Variable create​_drop​_stringify​_dialect Undocumented
Property info Info dictionary associated with the object, allowing user-defined data to be associated with this .SchemaItem.

Inherited from SchemaEventTarget (via DefaultGenerator, SchemaItem):

Method ​_set​_parent​_with​_dispatch Undocumented

Inherited from Traversible (via DefaultGenerator, SchemaItem):

Method get​_children Return immediate child .visitors.Traversible elements of this .visitors.Traversible.
Method __class​_getitem__ Undocumented
def __init__(self, name, start=None, increment=None, minvalue=None, maxvalue=None, nominvalue=None, nomaxvalue=None, cycle=None, schema=None, cache=None, order=None, data_type=None, optional=False, quote=None, metadata=None, quote_schema=None, for_update=False):
Construct a .Sequence object.
Parameters
namethe name of the sequence.
startthe starting index of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "START WITH" clause. If None, the clause is omitted, which on most platforms indicates a starting value of 1.
incrementthe increment value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "INCREMENT BY" clause. If None, the clause is omitted, which on most platforms indicates an increment of 1.
minvalue

the minimum value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "MINVALUE" clause. If None, the clause is omitted, which on most platforms indicates a minvalue of 1 and -2^63-1 for ascending and descending sequences, respectively.

New in version 1.0.7.
maxvalue

the maximum value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "MAXVALUE" clause. If None, the clause is omitted, which on most platforms indicates a maxvalue of 2^63-1 and -1 for ascending and descending sequences, respectively.

New in version 1.0.7.
nominvalue

no minimum value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "NO MINVALUE" clause. If None, the clause is omitted, which on most platforms indicates a minvalue of 1 and -2^63-1 for ascending and descending sequences, respectively.

New in version 1.0.7.
nomaxvalue

no maximum value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "NO MAXVALUE" clause. If None, the clause is omitted, which on most platforms indicates a maxvalue of 2^63-1 and -1 for ascending and descending sequences, respectively.

New in version 1.0.7.
cycle

allows the sequence to wrap around when the maxvalue or minvalue has been reached by an ascending or descending sequence respectively. This value is used when the CREATE SEQUENCE command is emitted to the database as the "CYCLE" clause. If the limit is reached, the next number generated will be the minvalue or maxvalue, respectively. If cycle=False (the default) any calls to nextval after the sequence has reached its maximum value will return an error.

New in version 1.0.7.
schemaoptional schema name for the sequence, if located in a schema other than the default. The rules for selecting the schema name when a _schema.MetaData is also present are the same as that of :paramref:`_schema.Table.schema`.
cache

optional integer value; number of future values in the sequence which are calculated in advance. Renders the CACHE keyword understood by Oracle and PostgreSQL.

New in version 1.1.12.
order

optional boolean value; if True, renders the ORDER keyword, understood by Oracle, indicating the sequence is definitively ordered. May be necessary to provide deterministic ordering using Oracle RAC.

New in version 1.1.12.
data​_type

The type to be returned by the sequence, for dialects that allow us to choose between INTEGER, BIGINT, etc. (e.g., mssql).

New in version 1.4.0.
optionalboolean value, when True, indicates that this .Sequence object only needs to be explicitly generated on backends that don't provide another way to generate primary key identifiers. Currently, it essentially means, "don't create this sequence on the PostgreSQL backend, where the SERIAL keyword creates a sequence for us automatically".
quoteboolean value, when True or False, explicitly forces quoting of the :paramref:`_schema.Sequence.name` on or off. When left at its default of None, normal quoting rules based on casing and reserved words take place.
metadata

optional _schema.MetaData object which this .Sequence will be associated with. A .Sequence that is associated with a _schema.MetaData gains the following capabilities:

  • The .Sequence will inherit the :paramref:`_schema.MetaData.schema` parameter specified to the target _schema.MetaData, which affects the production of CREATE / DROP DDL, if any.
  • The .Sequence.create and .Sequence.drop methods automatically use the engine bound to the _schema.MetaData object, if any.
  • The _schema.MetaData.create_all and _schema.MetaData.drop_all methods will emit CREATE / DROP for this .Sequence, even if the .Sequence is not associated with any _schema.Table / _schema.Column that's a member of this _schema.MetaData.

The above behaviors can only occur if the .Sequence is explicitly associated with the _schema.MetaData via this parameter.

See Also

:ref:`sequence_metadata` - full discussion of the :paramref:`.Sequence.metadata` parameter.

quote​_schemaSet the quoting preferences for the schema name.
for​_updateIndicates this .Sequence, when associated with a _schema.Column, should be invoked for UPDATE statements on that column's table, rather than for INSERT statements, when no value is otherwise present for that column in the statement.
def _not_a_column_expr(self):

Undocumented

def _set_metadata(self, metadata):

Undocumented

def _set_parent(self, column, **kw):
Associate with this SchemaEvent's parent object.
def _set_table(self, column, table):

Undocumented

def create(self, bind=None, checkfirst=True):

Creates this sequence in the database.

Note

the "bind" argument will be required in SQLAlchemy 2.0.

def drop(self, bind=None, checkfirst=True):

Drops this sequence from the database.

Note

the "bind" argument will be required in SQLAlchemy 2.0.

@util.preload_module('sqlalchemy.sql.functions')
def next_value(self):
Return a .next_value function element which will render the appropriate increment function for this .Sequence within any SQL expression.
__visit_name__: str =
is_sequence: bool =
_key =

Undocumented

data_type =

Undocumented

metadata =

Undocumented

name =

Undocumented

optional =

Undocumented

schema =

Undocumented

@property
bind =
Return the connectable associated with this default.
@util.memoized_property
is_callable =

Undocumented

@util.memoized_property
is_clause_element =

Undocumented