SQL.
Bases: sqlalchemy.types.TypeEngine, sqlalchemy.types.SchemaType
A bool datatype.
Boolean typically uses BOOLEAN or SMALLINT on the DDL side, and on the Python side deals in True or False.
Construct a Boolean.
Bases: sqlalchemy.types._DateAffinity, sqlalchemy.types.TypeEngine
A type for datetime.date() objects..
Construct an enum.
Keyword arguments which don’t apply to a specific backend are ignored by that backend.
Bases: sqlalchemy.types.Numeric
A type for float numbers.
Returns Python float objects by default, applying conversion as needed.
Construct a Float.
Bases: sqlalchemy.types._DateAffinity, sqlalchemy.types.TypeEngine
A type for int integers.).
Construct an Interval object.
Bases: sqlalchemy.types._Binary
A type for large binary byte data.
The Binary type generates BLOB or BYTEA when tables are created, and also converts incoming values using the Binary callable provided by each DB-API.
Construct a LargeBinary type.
Bases: sqlalchemy.types._DateAffinity, sqlalchemy.types.TypeEngine
A type for fixed precision numbers.
Typically generates DECIMAL or NUMERIC. Returns decimal.Decimal objects by default, applying conversion as needed.
Construct a Numeric.
When using the Numeric type, care should be taken to ensure that the asdecimal setting is apppropriate for the DBAPI in use - when Numeric applies a conversion from Decimal->float or float-> Decimal, this conversion incurs an additional performance overhead for all result columns received.
DBAPIs that return Decimal natively (e.g. psycopg2) will have better accuracy and higher performance with a setting of True, as the native translation to Decimal reduces the amount of floating- point issues at play, and the Numeric type itself doesn’t need to apply any further conversions. However, another DBAPI which returns floats natively will incur an additional conversion overhead, and is still subject to floating point data loss - in which case asdecimal=False will at least remove the extra conversion overhead.
Bases: sqlalchemy.types.MutableType,.
Note: be sure to read the notes for MutableType regarding ORM performance implications.
Construct a PickleType.
Bases: object
Mark a type as possibly requiring schema-level DDL for usage.
Supports types that must be explicitly created/dropped (i.e. PG ENUM type) as well as types that are complimented by table or schema level constraints, triggers, and other rules.
Bases: sqlalchemy.types.Integer
A type for smaller int integers.
Typically generates a SMALLINT in DDL, and otherwise acts like a normal Integer on the Python side..
Create a string-holding type.
Bases: sqlalchemy.types.String
A variably sized string type.
In SQL, usually corresponds to CLOB or TEXT. Can also take Python unicode objects and encode to the database’s encoding in bind params (and the reverse for result sets.)
Bases: sqlalchemy.types._DateAffinity, sqlalchemy.types.TypeEngine
A type for datetime.time() objects.
Bases: sqlalchemy.types.String
A variable length Unicode string.
The Unicode type is a String which converts Python unicode objects (i.e., strings that are defined as u'somevalue') into encoded bytestrings when passing the value to the database driver, and similarly decodes values from the database back into Python unicode objects.
It’s roughly equivalent to using a String object with convert_unicode=True, however the type has other significances in that it implies the usage of a unicode-capable type being used on the backend, such as NVARCHAR. This may affect what type is emitted when issuing CREATE TABLE and also may effect some DBAPI-specific details, such as type information passed along to setinputsizes().
When using the Unicode type, it is only appropriate to pass Python unicode objects, and not plain str. If a bytestring (str) is passed, a runtime warning is issued. If you notice your application raising these warnings but you’re not sure where, the Python warnings filter can be used to turn these warnings into exceptions which will illustrate a stack trace:
import warnings warnings.simplefilter('error')
Bytestrings sent to and received from the database are encoded using the dialect’s encoding, which defaults to utf-8.
Create a Unicode-converting String type.
Bases: sqlalchemy.types.Text
An unbounded-length Unicode string.
See Unicode for details on the unicode behavior of this object.
Like Unicode, usage the UnicodeText type implies a unicode-capable type being used on the backend, such as NCLOB.
Create a Unicode-converting Text type.
The SQL standard types always create database column types of the same name when CREATE TABLE is issued. Some types may not be supported on all databases.
Bases: sqlalchemy.types._Binary
The SQL BINARY type.
Bases: sqlalchemy.types.LargeBinary
The SQL BLOB type.
Bases: sqlalchemy.types.Boolean
The SQL BOOLEAN type.
Bases: sqlalchemy.types.String
The SQL CHAR type.
Bases: sqlalchemy.types.Text
The CLOB type.
This type is found in Oracle and Informix.
Bases: sqlalchemy.types.Date
The SQL DATE type.
Bases: sqlalchemy.types.DateTime
The SQL DATETIME type.
Bases: sqlalchemy.types.Numeric
The SQL DECIMAL type.
Bases: sqlalchemy.types.Float
The SQL FLOAT type.
Bases: sqlalchemy.types.Integer
The SQL INT or INTEGER type.
Bases: sqlalchemy.types.Unicode
The SQL NCHAR type.
Bases: sqlalchemy.types.Unicode
The SQL NVARCHAR type.
Bases: sqlalchemy.types.Numeric
The SQL NUMERIC type.
Bases: sqlalchemy.types.SmallInteger
The SQL SMALLINT type.
Bases: sqlalchemy.types.Text
The SQL TEXT type.
Bases: sqlalchemy.types.Time
The SQL TIME type.
Bases: sqlalchemy.types.DateTime
The SQL TIMESTAMP type.
Bases: sqlalchemy.types._Binary
The SQL VARBINARY type.
Bases: sqlalchemy.types.String
The SQL VARCHAR type.
Database-specific types are also available for import from each database’s dialect module. See the sqlalchemy.dialects reference for the database you’re interested in.
For example, MySQL has a BIGINTEGER type and PostgreSQL has an INET type. To use these, import them from the module explicitly:
from sqlalchemy.dialects import mysql table = Table('foo', meta, Column('id', mysql.BIGINTEGER), Column('enumerates', mysql.ENUM('a', 'b', 'c')) )
Or some PostgreSQL types:
from sqlalchemy.dialects import postgresql table = Table('foo', meta, Column('ipaddress', postgresql.INET), Column('elements', postgresql.ARRAY(str)) )')) )
User-defined types may be created to match special capabilities of a particular database or simply for implementing custom processing logic in Python.
The simplest method is implementing a TypeDecorator, a helper class that makes it easy to augment the bind parameter and result processing capabilities of one of the built in types.
To build a type object from scratch, subclass :class:UserDefinedType.
Bases: sqlalchemy.types.AbstractType): return MyType(self.impl.length)
The class-level “impl” variable is required, and can reference any TypeEngine class. Alternatively, the load_dialect_impl() method can be used to provide different type classes based on the dialect given; in this case, the “impl” variable can reference TypeEngine Integer variant, by with uses this type, this method will be called with the value operator.add and 35. The return value is whatever SQLAlchemy type should be used for 35 for this particular operation.
Loads the dialect-specific implementation of this type.
by default calls dialect.type_descriptor(self.impl), but can be overridden to provide different behavior.):)) )
A hook which allows the given operator to be adapted to something new.
See also UserDefinedType._adapt_expression(), an as-yet- semi-public method with greater capability in this regard..types.AbstractType
Base for built-in types..sql.visitors.Visitable
Defines a bind parameter processing function..
Defines a result-column processing function.
Bases: object
A mixin that marks a TypeEngine as representing a mutable Python object type.
“mutable” means that changes can occur in place to a value of this type. Examples includes Python lists, dictionaries, and sets, as well as user-defined objects. The primary need for identification of “mutable” types is by the ORM, which applies special rules to such values in order to guarantee that changes are detected. These rules may have a significant performance impact, described below.
A MutableType usually allows a flag called mutable=True to enable/disable the “mutability” flag, represented on this class by is_mutable(). Examples include PickleType and ARRAY. Setting this flag to False effectively disables any mutability- specific behavior by the ORM.
copy_value() and compare_values() represent a copy and compare function for values of this type - implementing subclasses should override these appropriately.
The usage of mutable types has significant performance implications when using the ORM. In order to detect changes, the ORM must create a copy of the value when it is first accessed, so that changes to the current value can be compared against the “clean” database-loaded value. Additionally, when the ORM checks to see if any data requires flushing, it must scan through all instances in the session which are known to have “mutable” attributes and compare the current value of each one to its “clean” value. So for example, if the Session contains 6000 objects (a fairly large amount) and autoflush is enabled, every individual execution of Query will require a full scan of that subset of the 6000 objects that have mutable attributes, possibly resulting in tens of thousands of additional method calls for every query.
Note that for small numbers (< 100 in the Session at a time) of objects with “mutable” values, the performance degradation is negligible. In most cases it’s likely that the convenience allowed by “mutable” change detection outweighs the performance penalty.
It is perfectly fine to represent “mutable” data types with the “mutable” flag set to False, which eliminates any performance issues. It means that the ORM will only reliably detect changes for values of this type if a newly modified value is of a different identity (i.e., id(value)) than what was present before - i.e., instead of operations like these:
myobject.somedict['foo'] = 'bar' myobject.someset.add('bar') myobject.somelist.append('bar')
You’d instead say:
myobject.somevalue = {'foo':'bar'} myobject.someset = myobject.someset.union(['bar']) myobject.somelist = myobject.somelist + ['bar']
A future release of SQLAlchemy will include instrumented collection support for mutable types, such that at least usage of plain Python datastructures will be able to emit events for in-place changes, removing the need for pessimistic scanning for changes.
Bases: object
A mixin that marks a type as supporting ‘concatenation’, typically strings..