VectorType#

class langchain_sqlserver.vectorstores.VectorType(length: int)[source]#

VectorType - A custom type definition.

__init__ for VectorType class.

Attributes

cache_ok

Indicate if statements using this ExternalType are "safe to cache".

ensure_kwarg

a regular expression that indicates method names for which the method should accept **kw arguments.

hashable

Flag, if False, means values from this type aren't hashable.

python_type

Return the Python type object expected to be returned by instances of this type, if known.

render_bind_cast

Render bind casts for BindTyping.RENDER_CASTS mode.

render_literal_cast

render casts when rendering a value as an inline literal, e.g. with TypeEngine.literal_processor().

should_evaluate_none

If True, the Python constant None is considered to be handled explicitly by this type.

sort_key_function

A sorting function that can be passed as the key to sorted.

Methods

__init__(length)

__init__ for VectorType class.

adapt(cls, **kw)

Produce an "adapted" form of this type, given an "impl" class to work with.

as_generic([allow_nulltype])

Return an instance of the generic type corresponding to this type using heuristic rule.

bind_expression(bindvalue)

Given a bind value (i.e. a BindParameter instance), return a SQL expression in its place.

bind_processor(dialect)

bind_processor function for VectorType class.

coerce_compared_value(op, value)

Suggest a type for a 'coerced' Python value in an expression.

column_expression(colexpr)

Given a SELECT column expression, return a wrapping SQL expression.

compare_values(x, y)

Compare two values for equality.

compile([dialect])

Produce a string-compiled form of this TypeEngine.

copy(**kw)

copy_value(value)

dialect_impl(dialect)

Return a dialect-specific implementation for this TypeEngine.

evaluates_none()

Return a copy of this type which has the should_evaluate_none flag set to True.

get_col_spec(**kw)

get_col_spec function for VectorType class.

get_dbapi_type(dbapi)

Return the corresponding type object from the underlying DB-API, if any.

literal_processor(dialect)

Return a conversion function for processing literal values that are to be rendered directly without using binds.

result_processor(dialect, coltype)

result_processor function for VectorType class.

with_variant(type_, *dialect_names)

Produce a copy of this type object that will utilize the given type when applied to the dialect of the given name.

Parameters:

length (int)

__init__(length: int) None[source]#

__init__ for VectorType class.

Parameters:

length (int)

Return type:

None

adapt(cls: Type[TypeEngine | TypeEngineMixin], **kw: Any) TypeEngine#

Produce an “adapted” form of this type, given an “impl” class to work with.

This method is used internally to associate generic types with “implementation” types that are specific to a particular dialect.

Parameters:
  • cls (Type[TypeEngine | TypeEngineMixin])

  • kw (Any)

Return type:

TypeEngine

as_generic(allow_nulltype: bool = False) TypeEngine#

Return an instance of the generic type corresponding to this type using heuristic rule. The method may be overridden if this heuristic rule is not sufficient.

>>> from sqlalchemy.dialects.mysql import INTEGER
>>> INTEGER(display_width=4).as_generic()
Integer()
>>> from sqlalchemy.dialects.mysql import NVARCHAR
>>> NVARCHAR(length=100).as_generic()
Unicode(length=100)

Added in version 1.4.0b2.

See also

metadata_reflection_dbagnostic_types - describes the use of _types.TypeEngine.as_generic() in conjunction with the _sql.DDLEvents.column_reflect() event, which is its intended use.

Parameters:

allow_nulltype (bool)

Return type:

TypeEngine

bind_expression(bindvalue: BindParameter[_T]) ColumnElement[_T] | None#

Given a bind value (i.e. a BindParameter instance), return a SQL expression in its place.

This is typically a SQL function that wraps the existing bound parameter within the statement. It is used for special data types that require literals being wrapped in some special database function in order to coerce an application-level value into a database-specific format. It is the SQL analogue of the TypeEngine.bind_processor() method.

This method is called during the SQL compilation phase of a statement, when rendering a SQL string. It is not called against specific values.

Note that this method, when implemented, should always return the exact same structure, without any conditional logic, as it may be used in an executemany() call against an arbitrary number of bound parameter sets.

Note

This method is only called relative to a dialect specific type object, which is often private to a dialect in use and is not the same type object as the public facing one, which means it’s not feasible to subclass a types.TypeEngine class in order to provide an alternate _types.TypeEngine.bind_expression() method, unless subclassing the _types.UserDefinedType class explicitly.

To provide alternate behavior for _types.TypeEngine.bind_expression(), implement a _types.TypeDecorator class and provide an implementation of _types.TypeDecorator.bind_expression().

See also

types_typedecorator

See also

types_sql_value_processing

Parameters:

bindvalue (BindParameter[_T])

Return type:

Optional[ColumnElement[_T]]

bind_processor(dialect: Any) Any[source]#

bind_processor function for VectorType class.

Parameters:

dialect (Any)

Return type:

Any

coerce_compared_value(op: OperatorType | None, value: Any) TypeEngine[Any]#

Suggest a type for a ‘coerced’ Python value in an expression.

Default behavior for UserDefinedType is the same as that of TypeDecorator; by default it returns self, assuming the compared value should be coerced into the same type as this one. See TypeDecorator.coerce_compared_value() for more detail.

Parameters:
  • op (Optional[OperatorType])

  • value (Any)

Return type:

TypeEngine[Any]

column_expression(colexpr: ColumnElement[_T]) ColumnElement[_T] | None#

Given a SELECT column expression, return a wrapping SQL expression.

This is typically a SQL function that wraps a column expression as rendered in the columns clause of a SELECT statement. It is used for special data types that require columns to be wrapped in some special database function in order to coerce the value before being sent back to the application. It is the SQL analogue of the TypeEngine.result_processor() method.

This method is called during the SQL compilation phase of a statement, when rendering a SQL string. It is not called against specific values.

Note

This method is only called relative to a dialect specific type object, which is often private to a dialect in use and is not the same type object as the public facing one, which means it’s not feasible to subclass a types.TypeEngine class in order to provide an alternate _types.TypeEngine.column_expression() method, unless subclassing the _types.UserDefinedType class explicitly.

To provide alternate behavior for _types.TypeEngine.column_expression(), implement a _types.TypeDecorator class and provide an implementation of _types.TypeDecorator.column_expression().

See also

types_typedecorator

See also

types_sql_value_processing

Parameters:

colexpr (ColumnElement[_T])

Return type:

Optional[ColumnElement[_T]]

compare_values(x: Any, y: Any) bool#

Compare two values for equality.

Parameters:
  • x (Any)

  • y (Any)

Return type:

bool

compile(dialect: Dialect | None = None) str#

Produce a string-compiled form of this TypeEngine.

When called with no arguments, uses a “default” dialect to produce a string result.

Parameters:

dialect (Optional[Dialect]) – a Dialect instance.

Return type:

str

copy(**kw: Any) Self#
Parameters:

kw (Any)

Return type:

Self

copy_value(value: Any) Any#
Parameters:

value (Any)

Return type:

Any

dialect_impl(dialect: Dialect) TypeEngine[_T]#

Return a dialect-specific implementation for this TypeEngine.

Parameters:

dialect (Dialect)

Return type:

TypeEngine[_T]

evaluates_none() Self#

Return a copy of this type which has the should_evaluate_none flag set to True.

E.g.:

Table(
    "some_table",
    metadata,
    Column(
        String(50).evaluates_none(),
        nullable=True,
        server_default="no value",
    ),
)

The ORM uses this flag to indicate that a positive value of None is passed to the column in an INSERT statement, rather than omitting the column from the INSERT statement which has the effect of firing off column-level defaults. It also allows for types which have special behavior associated with the Python None value to indicate that the value doesn’t necessarily translate into SQL NULL; a prime example of this is a JSON type which may wish to persist the JSON value 'null'.

In all cases, the actual NULL SQL value can be always be persisted in any column by using the _expression.null SQL construct in an INSERT statement or associated with an ORM-mapped attribute.

Note

The “evaluates none” flag does not apply to a value of None passed to :paramref:`_schema.Column.default` or :paramref:`_schema.Column.server_default`; in these cases, None still means “no default”.

See also

session_forcing_null - in the ORM documentation

:paramref:`.postgresql.JSON.none_as_null` - PostgreSQL JSON interaction with this flag.

TypeEngine.should_evaluate_none - class-level flag

Return type:

Self

get_col_spec(**kw: Any) str[source]#

get_col_spec function for VectorType class.

Parameters:

kw (Any)

Return type:

str

get_dbapi_type(dbapi: ModuleType) Any | None#

Return the corresponding type object from the underlying DB-API, if any.

This can be useful for calling setinputsizes(), for example.

Parameters:

dbapi (ModuleType)

Return type:

Any | None

literal_processor(dialect: Dialect) _LiteralProcessorType[_T] | None#

Return a conversion function for processing literal values that are to be rendered directly without using binds.

This function is used when the compiler makes use of the “literal_binds” flag, typically used in DDL generation as well as in certain scenarios where backends don’t accept bound parameters.

Returns a callable which will receive a literal Python value as the sole positional argument and will return a string representation to be rendered in a SQL statement.

Note

This method is only called relative to a dialect specific type object, which is often private to a dialect in use and is not the same type object as the public facing one, which means it’s not feasible to subclass a types.TypeEngine class in order to provide an alternate _types.TypeEngine.literal_processor() method, unless subclassing the _types.UserDefinedType class explicitly.

To provide alternate behavior for _types.TypeEngine.literal_processor(), implement a _types.TypeDecorator class and provide an implementation of _types.TypeDecorator.process_literal_param().

See also

types_typedecorator

Parameters:

dialect (Dialect)

Return type:

Optional[_LiteralProcessorType[_T]]

result_processor(dialect: Any, coltype: Any) Any[source]#

result_processor function for VectorType class.

Parameters:
  • dialect (Any)

  • coltype (Any)

Return type:

Any

with_variant(type_: _TypeEngineArgument[Any], *dialect_names: str) Self#

Produce a copy of this type object that will utilize the given type when applied to the dialect of the given name.

e.g.:

from sqlalchemy.types import String
from sqlalchemy.dialects import mysql

string_type = String()

string_type = string_type.with_variant(
    mysql.VARCHAR(collation="foo"), "mysql", "mariadb"
)

The variant mapping indicates that when this type is interpreted by a specific dialect, it will instead be transmuted into the given type, rather than using the primary type.

Changed in version 2.0: the _types.TypeEngine.with_variant() method now works with a _types.TypeEngine object “in place”, returning a copy of the original type rather than returning a wrapping object; the Variant class is no longer used.

Parameters:
  • type_ (_TypeEngineArgument[Any]) – a TypeEngine that will be selected as a variant from the originating type, when a dialect of the given name is in use.

  • *dialect_names (str) –

    one or more base names of the dialect which uses this type. (i.e. 'postgresql', 'mysql', etc.)

    Changed in version 2.0: multiple dialect names can be specified for one variant.

Return type:

Self

See also

types_with_variant - illustrates the use of _types.TypeEngine.with_variant().