class documentation

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_value 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_name__ Undocumented
Class Variable is_sequence Undocumented
Instance Variable column Undocumented
Instance Variable data_type Undocumented
Instance Variable metadata Undocumented
Instance Variable name Undocumented
Instance Variable optional Undocumented
Instance Variable schema Undocumented
Method _copy Undocumented
Method _not_a_column_expr Undocumented
Method _set_metadata Undocumented
Method _set_parent Associate with this SchemaEvent's parent object.
Method _set_table 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_callable Undocumented
Class Variable is_clause_element Undocumented
Class Variable is_scalar Undocumented
Class Variable is_server_default Undocumented
Instance Variable for_update Undocumented
Method _execute_on_connection Undocumented
Method _execute_on_scalar Undocumented
Class Variable _is_default_generator Undocumented

Inherited from Executable (via HasSchemaAttr, IdentityOptions, DefaultGenerator):

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.
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
Method _add_context_option Add a context option to this statement.
Method _compile_w_cache Undocumented
Method _set_compile_options Assign the compile options to a new value.
Method _update_compile_options update the _compile_options with new keys.
Class Variable _executable_traverse_internals Undocumented
Class Variable _with_context_options Undocumented
Class Variable _with_options Undocumented
Instance Variable _compile_options Undocumented
Instance Variable _execution_options Undocumented
Property _all_selected_columns Undocumented
Property _effective_plugin_target Undocumented

Inherited from StatementRole (via HasSchemaAttr, IdentityOptions, DefaultGenerator, Executable):

Class Variable __slots__ Undocumented
Class Variable _role_name Undocumented
Property _propagate_attrs Undocumented

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

Class Variable allows_lambda Undocumented
Class Variable uses_inspection Undocumented

Inherited from SchemaItem (via HasSchemaAttr, IdentityOptions, DefaultGenerator, Executable, StatementRole, SQLRole):

Method __repr__ 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 :class:`.SchemaItem`.
Method _init_items Initialize the list of child items for this SchemaItem.
Method _schema_item_copy Undocumented
Class Variable _use_schema_map Undocumented

Inherited from SchemaEventTarget (via HasSchemaAttr, IdentityOptions, DefaultGenerator, Executable, StatementRole, SQLRole, SchemaItem):

Class Variable dispatch Undocumented
Method _set_parent_with_dispatch Undocumented

Inherited from Visitable (via HasSchemaAttr, IdentityOptions, DefaultGenerator, Executable, StatementRole, SQLRole, SchemaItem, SchemaEventTarget, EventTarget):

Method __class_getitem__ Undocumented
Method __init_subclass__ Undocumented
Class Method _generate_compiler_dispatch Undocumented
Method _compiler_dispatch Undocumented
Class Variable _original_compiler_dispatch Undocumented
def __init__(self, name: 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.

def create(self, bind: _CreateDropBind, checkfirst: bool = True): (source)

Creates this sequence in the database.

def drop(self, bind: _CreateDropBind, checkfirst: bool = True): (source)

Drops this sequence from the database.

@util.preload_module('sqlalchemy.sql.functions')
def next_value(self) -> Function[int]: (source)

Return a :class:`.next_value` function element which will render the appropriate increment function for this :class:`.Sequence` within any SQL expression.

data_type = (source)

Undocumented

metadata = (source)

Undocumented

Undocumented

optional = (source)

Undocumented

def _not_a_column_expr(self) -> NoReturn: (source)

Undocumented

def _set_metadata(self, metadata: MetaData): (source)

Undocumented

def _set_parent(self, parent: SchemaEventTarget, **kw: Any): (source)

Associate with this SchemaEvent's parent object.

def _set_table(self, column: Column[Any], table: Table): (source)

Undocumented

Undocumented