class Sequence(HasSchemaAttr, IdentityOptions, DefaultGenerator): (source)
Represents a named database sequence. The :class:`.Sequence` object represents the name and configurational parameters of a database sequence. It also represents a construct that can be "executed" by a SQLAlchemy :class:`_engine.Engine` or :class:`_engine.Connection`, rendering the appropriate "next value" function for the target database and returning a result. The :class:`.Sequence` is typically associated with a primary key column:: some_table = Table( 'some_table', metadata, Column('id', Integer, Sequence('some_table_seq', start=1), primary_key=True) ) When CREATE TABLE is emitted for the above :class:`_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 :class:`.Sequence` construct is ignored. .. seealso:: :ref:`defaults_sequences` :class:`.CreateSequence` :class:`.DropSequence`
Method | __init__ |
Construct a :class:`.Sequence` object. |
Method | create |
Creates this sequence in the database. |
Method | drop |
Drops this sequence from the database. |
Method | next |
Return a :class:`.next_value` function element which will render the appropriate increment function for this :class:`.Sequence` within any SQL expression. |
Class Variable | __visit |
Undocumented |
Class Variable | is |
Undocumented |
Instance Variable | column |
Undocumented |
Instance Variable | data |
Undocumented |
Instance Variable | metadata |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | optional |
Undocumented |
Instance Variable | schema |
Undocumented |
Method | _copy |
Undocumented |
Method | _not |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Associate with this SchemaEvent's parent object. |
Method | _set |
Undocumented |
Instance Variable | _key |
Undocumented |
Inherited from IdentityOptions
(via HasSchemaAttr
):
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
(via HasSchemaAttr
, IdentityOptions
):
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Instance Variable | for |
Undocumented |
Method | _execute |
Undocumented |
Method | _execute |
Undocumented |
Class Variable | _is |
Undocumented |
Inherited from Executable
(via HasSchemaAttr
, IdentityOptions
, DefaultGenerator
):
Method | execution |
Set non-SQL options for the statement which take effect during execution. |
Method | get |
Get the non-SQL options which will take effect during execution. |
Method | options |
Apply options to this statement. |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | supports |
Undocumented |
Method | _add |
Add a context option to this statement. |
Method | _compile |
Undocumented |
Method | _set |
Assign the compile options to a new value. |
Method | _update |
update the _compile_options with new keys. |
Class Variable | _executable |
Undocumented |
Class Variable | _with |
Undocumented |
Class Variable | _with |
Undocumented |
Instance Variable | _compile |
Undocumented |
Instance Variable | _execution |
Undocumented |
Property | _all |
Undocumented |
Property | _effective |
Undocumented |
Inherited from StatementRole
(via HasSchemaAttr
, IdentityOptions
, DefaultGenerator
, Executable
):
Class Variable | __slots__ |
Undocumented |
Class Variable | _role |
Undocumented |
Property | _propagate |
Undocumented |
Inherited from SQLRole
(via HasSchemaAttr
, IdentityOptions
, DefaultGenerator
, Executable
, StatementRole
):
Class Variable | allows |
Undocumented |
Class Variable | uses |
Undocumented |
Inherited from SchemaItem
(via HasSchemaAttr
, IdentityOptions
, DefaultGenerator
, Executable
, StatementRole
, SQLRole
):
Method | __repr__ |
Undocumented |
Class Variable | create |
Undocumented |
Property | info |
Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.SchemaItem`. |
Method | _init |
Initialize the list of child items for this SchemaItem. |
Method | _schema |
Undocumented |
Class Variable | _use |
Undocumented |
Inherited from SchemaEventTarget
(via HasSchemaAttr
, IdentityOptions
, DefaultGenerator
, Executable
, StatementRole
, SQLRole
, SchemaItem
):
Class Variable | dispatch |
Undocumented |
Method | _set |
Undocumented |
Inherited from Visitable
(via HasSchemaAttr
, IdentityOptions
, DefaultGenerator
, Executable
, StatementRole
, SQLRole
, SchemaItem
, SchemaEventTarget
, EventTarget
):
Method | __class |
Undocumented |
Method | __init |
Undocumented |
Class Method | _generate |
Undocumented |
Method | _compiler |
Undocumented |
Class Variable | _original |
Undocumented |
str
, start: Optional[ int]
= None, increment: Optional[ int]
= None, minvalue: Optional[ int]
= None, maxvalue: Optional[ int]
= None, nominvalue: Optional[ bool]
= None, nomaxvalue: Optional[ bool]
= None, cycle: Optional[ bool]
= None, schema: Optional[ Union[ str, Literal[ SchemaConst.BLANK_SCHEMA]]]
= None, cache: Optional[ int]
= None, order: Optional[ bool]
= None, data_type: Optional[ _TypeEngineArgument[ int]]
= None, optional: bool
= False, quote: Optional[ bool]
= None, metadata: Optional[ MetaData]
= None, quote_schema: Optional[ bool]
= None, for_update: bool
= False):
(source)
¶
Construct a :class:`.Sequence` object. :param name: the name of the sequence. :param start: the 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. .. versionchanged:: 2.0 The :paramref:`.Sequence.start` parameter is required in order to have DDL emit "START WITH". This is a reversal of a change made in version 1.4 which would implicitly render "START WITH 1" if the :paramref:`.Sequence.start` were not included. See :ref:`change_7211` for more detail. :param increment: the 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. :param 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. .. versionadded:: 1.0.7 :param 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. .. versionadded:: 1.0.7 :param 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. .. versionadded:: 1.0.7 :param 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. .. versionadded:: 1.0.7 :param 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. .. versionadded:: 1.0.7 :param schema: optional schema name for the sequence, if located in a schema other than the default. The rules for selecting the schema name when a :class:`_schema.MetaData` is also present are the same as that of :paramref:`_schema.Table.schema`. :param 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. .. versionadded:: 1.1.12 :param 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. .. versionadded:: 1.1.12 :param data_type: The type to be returned by the sequence, for dialects that allow us to choose between INTEGER, BIGINT, etc. (e.g., mssql). .. versionadded:: 1.4.0 :param optional: boolean value, when ``True``, indicates that this :class:`.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". :param quote: boolean 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. :param quote_schema: Set the quoting preferences for the ``schema`` name. :param metadata: optional :class:`_schema.MetaData` object which this :class:`.Sequence` will be associated with. A :class:`.Sequence` that is associated with a :class:`_schema.MetaData` gains the following capabilities: * The :class:`.Sequence` will inherit the :paramref:`_schema.MetaData.schema` parameter specified to the target :class:`_schema.MetaData`, which affects the production of CREATE / DROP DDL, if any. * The :meth:`.Sequence.create` and :meth:`.Sequence.drop` methods automatically use the engine bound to the :class:`_schema.MetaData` object, if any. * The :meth:`_schema.MetaData.create_all` and :meth:`_schema.MetaData.drop_all` methods will emit CREATE / DROP for this :class:`.Sequence`, even if the :class:`.Sequence` is not associated with any :class:`_schema.Table` / :class:`_schema.Column` that's a member of this :class:`_schema.MetaData`. The above behaviors can only occur if the :class:`.Sequence` is explicitly associated with the :class:`_schema.MetaData` via this parameter. .. seealso:: :ref:`sequence_metadata` - full discussion of the :paramref:`.Sequence.metadata` parameter. :param for_update: Indicates this :class:`.Sequence`, when associated with a :class:`_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.
Return a :class:`.next_value` function element which will render the appropriate increment function for this :class:`.Sequence` within any SQL expression.