ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ 4]cg@sdZddlmZddlZddlZddlmZddlmZddlm Z ddlm Z dd l m Z dd l m Z dd l mZdd l mZdd l mZddl mZddl m ZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZyddlm Z!Wne"k re#Z!nXej$dej%Z&ej$dej%ej'BZ(e)dddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddgfZ*ddfZ+ddddfZ,dddddddfZ-dej.fdYZ/dej0fdYZ1dej2fdYZ3e3Z4dej2fdYZ5e5Z6dej2fdYZ7e7Z8dej2fdYZ9dej2fdYZ:dej2fdYZ;dej<fdYZ<dej=fdYZ=dej>ej?fdYZ@e@ZAdej2fdYZBeBZCdej2fdYZ e ZDdej2fdYZEdej>ejFfdYZGie@ejH6eGejF6ZIi ed6ed6ed6ed6ed6ejJd6ejJd6ed6ed6ed6ed6e3d6e5d6e d6eBd6eBd6e7d6e9d6e:d6e;d6e1d6e<d6e<d6e<d6e=d6e=d6ed6e=d6e/d6ed6e@d6eEd6ZKdejLfdYZMdejNfdYZOdejPfdYZQdejRfdYZSde jTfdYZUdejVfdYZWdejVfdYZXde jYfdYZZde j[fdYZ\dS(s .. dialect:: postgresql :name: PostgreSQL .. _postgresql_sequences: Sequences/SERIAL/IDENTITY ------------------------- PostgreSQL supports sequences, and SQLAlchemy uses these as the default means of creating new primary key values for integer-based primary key columns. When creating tables, SQLAlchemy will issue the ``SERIAL`` datatype for integer-based primary key columns, which generates a sequence and server side default corresponding to the column. To specify a specific named sequence to be used for primary key generation, use the :func:`~sqlalchemy.schema.Sequence` construct:: Table('sometable', metadata, Column('id', Integer, Sequence('some_id_seq'), primary_key=True) ) When SQLAlchemy issues a single INSERT statement, to fulfill the contract of having the "last insert identifier" available, a RETURNING clause is added to the INSERT statement which specifies the primary key columns should be returned after the statement completes. The RETURNING functionality only takes place if PostgreSQL 8.2 or later is in use. As a fallback approach, the sequence, whether specified explicitly or implicitly via ``SERIAL``, is executed independently beforehand, the returned value to be used in the subsequent insert. Note that when an :func:`~sqlalchemy.sql.expression.insert()` construct is executed using "executemany" semantics, the "last inserted identifier" functionality does not apply; no RETURNING clause is emitted nor is the sequence pre-executed in this case. To force the usage of RETURNING by default off, specify the flag ``implicit_returning=False`` to :func:`.create_engine`. PostgreSQL 10 IDENTITY columns ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PostgreSQL 10 has a new IDENTITY feature that supersedes the use of SERIAL. Built-in support for rendering of IDENTITY is not available yet, however the following compilation hook may be used to replace occurrences of SERIAL with IDENTITY:: from sqlalchemy.schema import CreateColumn from sqlalchemy.ext.compiler import compiles @compiles(CreateColumn, 'postgresql') def use_identity(element, compiler, **kw): text = compiler.visit_create_column(element, **kw) text = text.replace("SERIAL", "INT GENERATED BY DEFAULT AS IDENTITY") return text Using the above, a table such as:: t = Table( 't', m, Column('id', Integer, primary_key=True), Column('data', String) ) Will generate on the backing database as:: CREATE TABLE t ( id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, data VARCHAR, PRIMARY KEY (id) ) .. _postgresql_isolation_level: Transaction Isolation Level --------------------------- All PostgreSQL dialects support setting of transaction isolation level both via a dialect-specific parameter :paramref:`.create_engine.isolation_level` accepted by :func:`.create_engine`, as well as the :paramref:`.Connection.execution_options.isolation_level` argument as passed to :meth:`.Connection.execution_options`. When using a non-psycopg2 dialect, this feature works by issuing the command ``SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL `` for each new connection. For the special AUTOCOMMIT isolation level, DBAPI-specific techniques are used. To set isolation level using :func:`.create_engine`:: engine = create_engine( "postgresql+pg8000://scott:tiger@localhost/test", isolation_level="READ UNCOMMITTED" ) To set using per-connection execution options:: connection = engine.connect() connection = connection.execution_options( isolation_level="READ COMMITTED" ) Valid values for ``isolation_level`` include: * ``READ COMMITTED`` * ``READ UNCOMMITTED`` * ``REPEATABLE READ`` * ``SERIALIZABLE`` * ``AUTOCOMMIT`` - on psycopg2 / pg8000 only .. seealso:: :ref:`psycopg2_isolation_level` :ref:`pg8000_isolation_level` .. _postgresql_schema_reflection: Remote-Schema Table Introspection and PostgreSQL search_path ------------------------------------------------------------ **TL;DR;**: keep the ``search_path`` variable set to its default of ``public``, name schemas **other** than ``public`` explicitly within ``Table`` definitions. The PostgreSQL dialect can reflect tables from any schema. The :paramref:`.Table.schema` argument, or alternatively the :paramref:`.MetaData.reflect.schema` argument determines which schema will be searched for the table or tables. The reflected :class:`.Table` objects will in all cases retain this ``.schema`` attribute as was specified. However, with regards to tables which these :class:`.Table` objects refer to via foreign key constraint, a decision must be made as to how the ``.schema`` is represented in those remote tables, in the case where that remote schema name is also a member of the current `PostgreSQL search path `_. By default, the PostgreSQL dialect mimics the behavior encouraged by PostgreSQL's own ``pg_get_constraintdef()`` builtin procedure. This function returns a sample definition for a particular foreign key constraint, omitting the referenced schema name from that definition when the name is also in the PostgreSQL schema search path. The interaction below illustrates this behavior:: test=> CREATE TABLE test_schema.referred(id INTEGER PRIMARY KEY); CREATE TABLE test=> CREATE TABLE referring( test(> id INTEGER PRIMARY KEY, test(> referred_id INTEGER REFERENCES test_schema.referred(id)); CREATE TABLE test=> SET search_path TO public, test_schema; test=> SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM test-> pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n test-> ON n.oid = c.relnamespace test-> JOIN pg_catalog.pg_constraint r ON c.oid = r.conrelid test-> WHERE c.relname='referring' AND r.contype = 'f' test-> ; pg_get_constraintdef --------------------------------------------------- FOREIGN KEY (referred_id) REFERENCES referred(id) (1 row) Above, we created a table ``referred`` as a member of the remote schema ``test_schema``, however when we added ``test_schema`` to the PG ``search_path`` and then asked ``pg_get_constraintdef()`` for the ``FOREIGN KEY`` syntax, ``test_schema`` was not included in the output of the function. On the other hand, if we set the search path back to the typical default of ``public``:: test=> SET search_path TO public; SET The same query against ``pg_get_constraintdef()`` now returns the fully schema-qualified name for us:: test=> SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM test-> pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n test-> ON n.oid = c.relnamespace test-> JOIN pg_catalog.pg_constraint r ON c.oid = r.conrelid test-> WHERE c.relname='referring' AND r.contype = 'f'; pg_get_constraintdef --------------------------------------------------------------- FOREIGN KEY (referred_id) REFERENCES test_schema.referred(id) (1 row) SQLAlchemy will by default use the return value of ``pg_get_constraintdef()`` in order to determine the remote schema name. That is, if our ``search_path`` were set to include ``test_schema``, and we invoked a table reflection process as follows:: >>> from sqlalchemy import Table, MetaData, create_engine >>> engine = create_engine("postgresql://scott:tiger@localhost/test") >>> with engine.connect() as conn: ... conn.execute("SET search_path TO test_schema, public") ... meta = MetaData() ... referring = Table('referring', meta, ... autoload=True, autoload_with=conn) ... The above process would deliver to the :attr:`.MetaData.tables` collection ``referred`` table named **without** the schema:: >>> meta.tables['referred'].schema is None True To alter the behavior of reflection such that the referred schema is maintained regardless of the ``search_path`` setting, use the ``postgresql_ignore_search_path`` option, which can be specified as a dialect-specific argument to both :class:`.Table` as well as :meth:`.MetaData.reflect`:: >>> with engine.connect() as conn: ... conn.execute("SET search_path TO test_schema, public") ... meta = MetaData() ... referring = Table('referring', meta, autoload=True, ... autoload_with=conn, ... postgresql_ignore_search_path=True) ... We will now have ``test_schema.referred`` stored as schema-qualified:: >>> meta.tables['test_schema.referred'].schema 'test_schema' .. sidebar:: Best Practices for PostgreSQL Schema reflection The description of PostgreSQL schema reflection behavior is complex, and is the product of many years of dealing with widely varied use cases and user preferences. But in fact, there's no need to understand any of it if you just stick to the simplest use pattern: leave the ``search_path`` set to its default of ``public`` only, never refer to the name ``public`` as an explicit schema name otherwise, and refer to all other schema names explicitly when building up a :class:`.Table` object. The options described here are only for those users who can't, or prefer not to, stay within these guidelines. Note that **in all cases**, the "default" schema is always reflected as ``None``. The "default" schema on PostgreSQL is that which is returned by the PostgreSQL ``current_schema()`` function. On a typical PostgreSQL installation, this is the name ``public``. So a table that refers to another which is in the ``public`` (i.e. default) schema will always have the ``.schema`` attribute set to ``None``. .. versionadded:: 0.9.2 Added the ``postgresql_ignore_search_path`` dialect-level option accepted by :class:`.Table` and :meth:`.MetaData.reflect`. .. seealso:: `The Schema Search Path `_ - on the PostgreSQL website. INSERT/UPDATE...RETURNING ------------------------- The dialect supports PG 8.2's ``INSERT..RETURNING``, ``UPDATE..RETURNING`` and ``DELETE..RETURNING`` syntaxes. ``INSERT..RETURNING`` is used by default for single-row INSERT statements in order to fetch newly generated primary key identifiers. To specify an explicit ``RETURNING`` clause, use the :meth:`._UpdateBase.returning` method on a per-statement basis:: # INSERT..RETURNING result = table.insert().returning(table.c.col1, table.c.col2).\ values(name='foo') print result.fetchall() # UPDATE..RETURNING result = table.update().returning(table.c.col1, table.c.col2).\ where(table.c.name=='foo').values(name='bar') print result.fetchall() # DELETE..RETURNING result = table.delete().returning(table.c.col1, table.c.col2).\ where(table.c.name=='foo') print result.fetchall() .. _postgresql_insert_on_conflict: INSERT...ON CONFLICT (Upsert) ------------------------------ Starting with version 9.5, PostgreSQL allows "upserts" (update or insert) of rows into a table via the ``ON CONFLICT`` clause of the ``INSERT`` statement. A candidate row will only be inserted if that row does not violate any unique constraints. In the case of a unique constraint violation, a secondary action can occur which can be either "DO UPDATE", indicating that the data in the target row should be updated, or "DO NOTHING", which indicates to silently skip this row. Conflicts are determined using existing unique constraints and indexes. These constraints may be identified either using their name as stated in DDL, or they may be *inferred* by stating the columns and conditions that comprise the indexes. SQLAlchemy provides ``ON CONFLICT`` support via the PostgreSQL-specific :func:`.postgresql.dml.insert()` function, which provides the generative methods :meth:`~.postgresql.dml.Insert.on_conflict_do_update` and :meth:`~.postgresql.dml.Insert.on_conflict_do_nothing`:: from sqlalchemy.dialects.postgresql import insert insert_stmt = insert(my_table).values( id='some_existing_id', data='inserted value') do_nothing_stmt = insert_stmt.on_conflict_do_nothing( index_elements=['id'] ) conn.execute(do_nothing_stmt) do_update_stmt = insert_stmt.on_conflict_do_update( constraint='pk_my_table', set_=dict(data='updated value') ) conn.execute(do_update_stmt) Both methods supply the "target" of the conflict using either the named constraint or by column inference: * The :paramref:`.Insert.on_conflict_do_update.index_elements` argument specifies a sequence containing string column names, :class:`.Column` objects, and/or SQL expression elements, which would identify a unique index:: do_update_stmt = insert_stmt.on_conflict_do_update( index_elements=['id'], set_=dict(data='updated value') ) do_update_stmt = insert_stmt.on_conflict_do_update( index_elements=[my_table.c.id], set_=dict(data='updated value') ) * When using :paramref:`.Insert.on_conflict_do_update.index_elements` to infer an index, a partial index can be inferred by also specifying the use the :paramref:`.Insert.on_conflict_do_update.index_where` parameter:: from sqlalchemy.dialects.postgresql import insert stmt = insert(my_table).values(user_email='a@b.com', data='inserted data') stmt = stmt.on_conflict_do_update( index_elements=[my_table.c.user_email], index_where=my_table.c.user_email.like('%@gmail.com'), set_=dict(data=stmt.excluded.data) ) conn.execute(stmt) * The :paramref:`.Insert.on_conflict_do_update.constraint` argument is used to specify an index directly rather than inferring it. This can be the name of a UNIQUE constraint, a PRIMARY KEY constraint, or an INDEX:: do_update_stmt = insert_stmt.on_conflict_do_update( constraint='my_table_idx_1', set_=dict(data='updated value') ) do_update_stmt = insert_stmt.on_conflict_do_update( constraint='my_table_pk', set_=dict(data='updated value') ) * The :paramref:`.Insert.on_conflict_do_update.constraint` argument may also refer to a SQLAlchemy construct representing a constraint, e.g. :class:`.UniqueConstraint`, :class:`.PrimaryKeyConstraint`, :class:`.Index`, or :class:`.ExcludeConstraint`. In this use, if the constraint has a name, it is used directly. Otherwise, if the constraint is unnamed, then inference will be used, where the expressions and optional WHERE clause of the constraint will be spelled out in the construct. This use is especially convenient to refer to the named or unnamed primary key of a :class:`.Table` using the :attr:`.Table.primary_key` attribute:: do_update_stmt = insert_stmt.on_conflict_do_update( constraint=my_table.primary_key, set_=dict(data='updated value') ) ``ON CONFLICT...DO UPDATE`` is used to perform an update of the already existing row, using any combination of new values as well as values from the proposed insertion. These values are specified using the :paramref:`.Insert.on_conflict_do_update.set_` parameter. This parameter accepts a dictionary which consists of direct values for UPDATE:: from sqlalchemy.dialects.postgresql import insert stmt = insert(my_table).values(id='some_id', data='inserted value') do_update_stmt = stmt.on_conflict_do_update( index_elements=['id'], set_=dict(data='updated value') ) conn.execute(do_update_stmt) .. warning:: The :meth:`.Insert.on_conflict_do_update` method does **not** take into account Python-side default UPDATE values or generation functions, e.g. e.g. those specified using :paramref:`.Column.onupdate`. These values will not be exercised for an ON CONFLICT style of UPDATE, unless they are manually specified in the :paramref:`.Insert.on_conflict_do_update.set_` dictionary. In order to refer to the proposed insertion row, the special alias :attr:`~.postgresql.dml.Insert.excluded` is available as an attribute on the :class:`.postgresql.dml.Insert` object; this object is a :class:`.ColumnCollection` which alias contains all columns of the target table:: from sqlalchemy.dialects.postgresql import insert stmt = insert(my_table).values( id='some_id', data='inserted value', author='jlh') do_update_stmt = stmt.on_conflict_do_update( index_elements=['id'], set_=dict(data='updated value', author=stmt.excluded.author) ) conn.execute(do_update_stmt) The :meth:`.Insert.on_conflict_do_update` method also accepts a WHERE clause using the :paramref:`.Insert.on_conflict_do_update.where` parameter, which will limit those rows which receive an UPDATE:: from sqlalchemy.dialects.postgresql import insert stmt = insert(my_table).values( id='some_id', data='inserted value', author='jlh') on_update_stmt = stmt.on_conflict_do_update( index_elements=['id'], set_=dict(data='updated value', author=stmt.excluded.author) where=(my_table.c.status == 2) ) conn.execute(on_update_stmt) ``ON CONFLICT`` may also be used to skip inserting a row entirely if any conflict with a unique or exclusion constraint occurs; below this is illustrated using the :meth:`~.postgresql.dml.Insert.on_conflict_do_nothing` method:: from sqlalchemy.dialects.postgresql import insert stmt = insert(my_table).values(id='some_id', data='inserted value') stmt = stmt.on_conflict_do_nothing(index_elements=['id']) conn.execute(stmt) If ``DO NOTHING`` is used without specifying any columns or constraint, it has the effect of skipping the INSERT for any unique or exclusion constraint violation which occurs:: from sqlalchemy.dialects.postgresql import insert stmt = insert(my_table).values(id='some_id', data='inserted value') stmt = stmt.on_conflict_do_nothing() conn.execute(stmt) .. versionadded:: 1.1 Added support for PostgreSQL ON CONFLICT clauses .. seealso:: `INSERT .. ON CONFLICT `_ - in the PostgreSQL documentation. .. _postgresql_match: Full Text Search ---------------- SQLAlchemy makes available the PostgreSQL ``@@`` operator via the :meth:`.ColumnElement.match` method on any textual column expression. On a PostgreSQL dialect, an expression like the following:: select([sometable.c.text.match("search string")]) will emit to the database:: SELECT text @@ to_tsquery('search string') FROM table The PostgreSQL text search functions such as ``to_tsquery()`` and ``to_tsvector()`` are available explicitly using the standard :data:`.func` construct. For example:: select([ func.to_tsvector('fat cats ate rats').match('cat & rat') ]) Emits the equivalent of:: SELECT to_tsvector('fat cats ate rats') @@ to_tsquery('cat & rat') The :class:`.postgresql.TSVECTOR` type can provide for explicit CAST:: from sqlalchemy.dialects.postgresql import TSVECTOR from sqlalchemy import select, cast select([cast("some text", TSVECTOR)]) produces a statement equivalent to:: SELECT CAST('some text' AS TSVECTOR) AS anon_1 Full Text Searches in PostgreSQL are influenced by a combination of: the PostgreSQL setting of ``default_text_search_config``, the ``regconfig`` used to build the GIN/GiST indexes, and the ``regconfig`` optionally passed in during a query. When performing a Full Text Search against a column that has a GIN or GiST index that is already pre-computed (which is common on full text searches) one may need to explicitly pass in a particular PostgreSQL ``regconfig`` value to ensure the query-planner utilizes the index and does not re-compute the column on demand. In order to provide for this explicit query planning, or to use different search strategies, the ``match`` method accepts a ``postgresql_regconfig`` keyword argument:: select([mytable.c.id]).where( mytable.c.title.match('somestring', postgresql_regconfig='english') ) Emits the equivalent of:: SELECT mytable.id FROM mytable WHERE mytable.title @@ to_tsquery('english', 'somestring') One can also specifically pass in a `'regconfig'` value to the ``to_tsvector()`` command as the initial argument:: select([mytable.c.id]).where( func.to_tsvector('english', mytable.c.title )\ .match('somestring', postgresql_regconfig='english') ) produces a statement equivalent to:: SELECT mytable.id FROM mytable WHERE to_tsvector('english', mytable.title) @@ to_tsquery('english', 'somestring') It is recommended that you use the ``EXPLAIN ANALYZE...`` tool from PostgreSQL to ensure that you are generating queries with SQLAlchemy that take full advantage of any indexes you may have created for full text search. FROM ONLY ... ------------------------ The dialect supports PostgreSQL's ONLY keyword for targeting only a particular table in an inheritance hierarchy. This can be used to produce the ``SELECT ... FROM ONLY``, ``UPDATE ONLY ...``, and ``DELETE FROM ONLY ...`` syntaxes. It uses SQLAlchemy's hints mechanism:: # SELECT ... FROM ONLY ... result = table.select().with_hint(table, 'ONLY', 'postgresql') print result.fetchall() # UPDATE ONLY ... table.update(values=dict(foo='bar')).with_hint('ONLY', dialect_name='postgresql') # DELETE FROM ONLY ... table.delete().with_hint('ONLY', dialect_name='postgresql') .. _postgresql_indexes: PostgreSQL-Specific Index Options --------------------------------- Several extensions to the :class:`.Index` construct are available, specific to the PostgreSQL dialect. .. _postgresql_partial_indexes: Partial Indexes ^^^^^^^^^^^^^^^ Partial indexes add criterion to the index definition so that the index is applied to a subset of rows. These can be specified on :class:`.Index` using the ``postgresql_where`` keyword argument:: Index('my_index', my_table.c.id, postgresql_where=my_table.c.value > 10) Operator Classes ^^^^^^^^^^^^^^^^ PostgreSQL allows the specification of an *operator class* for each column of an index (see http://www.postgresql.org/docs/8.3/interactive/indexes-opclass.html). The :class:`.Index` construct allows these to be specified via the ``postgresql_ops`` keyword argument:: Index( 'my_index', my_table.c.id, my_table.c.data, postgresql_ops={ 'data': 'text_pattern_ops', 'id': 'int4_ops' }) Note that the keys in the ``postgresql_ops`` dictionary are the "key" name of the :class:`.Column`, i.e. the name used to access it from the ``.c`` collection of :class:`.Table`, which can be configured to be different than the actual name of the column as expressed in the database. If ``postgresql_ops`` is to be used against a complex SQL expression such as a function call, then to apply to the column it must be given a label that is identified in the dictionary by name, e.g.:: Index( 'my_index', my_table.c.id, func.lower(my_table.c.data).label('data_lower'), postgresql_ops={ 'data_lower': 'text_pattern_ops', 'id': 'int4_ops' }) Index Types ^^^^^^^^^^^ PostgreSQL provides several index types: B-Tree, Hash, GiST, and GIN, as well as the ability for users to create their own (see http://www.postgresql.org/docs/8.3/static/indexes-types.html). These can be specified on :class:`.Index` using the ``postgresql_using`` keyword argument:: Index('my_index', my_table.c.data, postgresql_using='gin') The value passed to the keyword argument will be simply passed through to the underlying CREATE INDEX command, so it *must* be a valid index type for your version of PostgreSQL. .. _postgresql_index_storage: Index Storage Parameters ^^^^^^^^^^^^^^^^^^^^^^^^ PostgreSQL allows storage parameters to be set on indexes. The storage parameters available depend on the index method used by the index. Storage parameters can be specified on :class:`.Index` using the ``postgresql_with`` keyword argument:: Index('my_index', my_table.c.data, postgresql_with={"fillfactor": 50}) .. versionadded:: 1.0.6 PostgreSQL allows to define the tablespace in which to create the index. The tablespace can be specified on :class:`.Index` using the ``postgresql_tablespace`` keyword argument:: Index('my_index', my_table.c.data, postgresql_tablespace='my_tablespace') .. versionadded:: 1.1 Note that the same option is available on :class:`.Table` as well. .. _postgresql_index_concurrently: Indexes with CONCURRENTLY ^^^^^^^^^^^^^^^^^^^^^^^^^ The PostgreSQL index option CONCURRENTLY is supported by passing the flag ``postgresql_concurrently`` to the :class:`.Index` construct:: tbl = Table('testtbl', m, Column('data', Integer)) idx1 = Index('test_idx1', tbl.c.data, postgresql_concurrently=True) The above index construct will render DDL for CREATE INDEX, assuming PostgreSQL 8.2 or higher is detected or for a connection-less dialect, as:: CREATE INDEX CONCURRENTLY test_idx1 ON testtbl (data) For DROP INDEX, assuming PostgreSQL 9.2 or higher is detected or for a connection-less dialect, it will emit:: DROP INDEX CONCURRENTLY test_idx1 .. versionadded:: 1.1 support for CONCURRENTLY on DROP INDEX. The CONCURRENTLY keyword is now only emitted if a high enough version of PostgreSQL is detected on the connection (or for a connection-less dialect). When using CONCURRENTLY, the PostgreSQL database requires that the statement be invoked outside of a transaction block. The Python DBAPI enforces that even for a single statement, a transaction is present, so to use this construct, the DBAPI's "autocommit" mode must be used:: metadata = MetaData() table = Table( "foo", metadata, Column("id", String)) index = Index( "foo_idx", table.c.id, postgresql_concurrently=True) with engine.connect() as conn: with conn.execution_options(isolation_level='AUTOCOMMIT'): table.create(conn) .. seealso:: :ref:`postgresql_isolation_level` .. _postgresql_index_reflection: PostgreSQL Index Reflection --------------------------- The PostgreSQL database creates a UNIQUE INDEX implicitly whenever the UNIQUE CONSTRAINT construct is used. When inspecting a table using :class:`.Inspector`, the :meth:`.Inspector.get_indexes` and the :meth:`.Inspector.get_unique_constraints` will report on these two constructs distinctly; in the case of the index, the key ``duplicates_constraint`` will be present in the index entry if it is detected as mirroring a constraint. When performing reflection using ``Table(..., autoload=True)``, the UNIQUE INDEX is **not** returned in :attr:`.Table.indexes` when it is detected as mirroring a :class:`.UniqueConstraint` in the :attr:`.Table.constraints` collection. .. versionchanged:: 1.0.0 - :class:`.Table` reflection now includes :class:`.UniqueConstraint` objects present in the :attr:`.Table.constraints` collection; the PostgreSQL backend will no longer include a "mirrored" :class:`.Index` construct in :attr:`.Table.indexes` if it is detected as corresponding to a unique constraint. Special Reflection Options -------------------------- The :class:`.Inspector` used for the PostgreSQL backend is an instance of :class:`.PGInspector`, which offers additional methods:: from sqlalchemy import create_engine, inspect engine = create_engine("postgresql+psycopg2://localhost/test") insp = inspect(engine) # will be a PGInspector print(insp.get_enums()) .. autoclass:: PGInspector :members: .. _postgresql_table_options: PostgreSQL Table Options ------------------------ Several options for CREATE TABLE are supported directly by the PostgreSQL dialect in conjunction with the :class:`.Table` construct: * ``TABLESPACE``:: Table("some_table", metadata, ..., postgresql_tablespace='some_tablespace') The above option is also available on the :class:`.Index` construct. * ``ON COMMIT``:: Table("some_table", metadata, ..., postgresql_on_commit='PRESERVE ROWS') * ``WITH OIDS``:: Table("some_table", metadata, ..., postgresql_with_oids=True) * ``WITHOUT OIDS``:: Table("some_table", metadata, ..., postgresql_with_oids=False) * ``INHERITS``:: Table("some_table", metadata, ..., postgresql_inherits="some_supertable") Table("some_table", metadata, ..., postgresql_inherits=("t1", "t2", ...)) .. versionadded:: 1.0.0 * ``PARTITION BY``:: Table("some_table", metadata, ..., postgresql_partition_by='LIST (part_column)') .. versionadded:: 1.2.6 .. seealso:: `PostgreSQL CREATE TABLE options `_ ARRAY Types ----------- The PostgreSQL dialect supports arrays, both as multidimensional column types as well as array literals: * :class:`.postgresql.ARRAY` - ARRAY datatype * :class:`.postgresql.array` - array literal * :func:`.postgresql.array_agg` - ARRAY_AGG SQL function * :class:`.postgresql.aggregate_order_by` - helper for PG's ORDER BY aggregate function syntax. JSON Types ---------- The PostgreSQL dialect supports both JSON and JSONB datatypes, including psycopg2's native support and support for all of PostgreSQL's special operators: * :class:`.postgresql.JSON` * :class:`.postgresql.JSONB` HSTORE Type ----------- The PostgreSQL HSTORE type as well as hstore literals are supported: * :class:`.postgresql.HSTORE` - HSTORE datatype * :class:`.postgresql.hstore` - hstore literal ENUM Types ---------- PostgreSQL has an independently creatable TYPE structure which is used to implement an enumerated type. This approach introduces significant complexity on the SQLAlchemy side in terms of when this type should be CREATED and DROPPED. The type object is also an independently reflectable entity. The following sections should be consulted: * :class:`.postgresql.ENUM` - DDL and typing support for ENUM. * :meth:`.PGInspector.get_enums` - retrieve a listing of current ENUM types * :meth:`.postgresql.ENUM.create` , :meth:`.postgresql.ENUM.drop` - individual CREATE and DROP commands for ENUM. .. _postgresql_array_of_enum: Using ENUM with ARRAY ^^^^^^^^^^^^^^^^^^^^^ The combination of ENUM and ARRAY is not directly supported by backend DBAPIs at this time. In order to send and receive an ARRAY of ENUM, use the following workaround type, which decorates the :class:`.postgresql.ARRAY` datatype. .. sourcecode:: python from sqlalchemy import TypeDecorator from sqlalchemy.dialects.postgresql import ARRAY class ArrayOfEnum(TypeDecorator): impl = ARRAY def bind_expression(self, bindvalue): return sa.cast(bindvalue, self) def result_processor(self, dialect, coltype): super_rp = super(ArrayOfEnum, self).result_processor( dialect, coltype) def handle_raw_string(value): inner = re.match(r"^{(.*)}$", value).group(1) return inner.split(",") if inner else [] def process(value): if value is None: return None return super_rp(handle_raw_string(value)) return process E.g.:: Table( 'mydata', metadata, Column('id', Integer, primary_key=True), Column('data', ArrayOfEnum(ENUM('a', 'b, 'c', name='myenum'))) ) This type is not included as a built-in type as it would be incompatible with a DBAPI that suddenly decides to support ARRAY of ENUM directly in a new version. .. _postgresql_array_of_json: Using JSON/JSONB with ARRAY ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Similar to using ENUM, for an ARRAY of JSON/JSONB we need to render the appropriate CAST, however current psycopg2 drivers seem to handle the result for ARRAY of JSON automatically, so the type is simpler:: class CastingArray(ARRAY): def bind_expression(self, bindvalue): return sa.cast(bindvalue, self) E.g.:: Table( 'mydata', metadata, Column('id', Integer, primary_key=True), Column('data', CastingArray(JSONB)) ) i(t defaultdictNi(texc(tschema(tsql(tutil(tdefault(t reflection(tcompiler(telements(t expression(tsqltypes(tBIGINT(tBOOLEAN(tCHAR(tDATE(tFLOAT(tINTEGER(tNUMERIC(tREAL(tSMALLINT(tTEXT(tVARCHAR(tUUIDs ^(?:btree|hash|gist|gin|[\w_]+)$ss\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER|GRANT|REVOKE|IMPORT FOREIGN SCHEMA|REFRESH MATERIALIZED VIEW|TRUNCATE)talltanalysetanalyzetandtanytarraytastasct asymmetrictbothtcasetcasttchecktcollatetcolumnt constrainttcreatetcurrent_catalogt current_datet current_rolet current_timetcurrent_timestampt current_userRt deferrabletdesctdistincttdotelsetendtexcepttfalsetfetchtfortforeigntfromtgranttgroupthavingtint initiallyt intersecttintotleadingtlimitt localtimetlocaltimestamptnewtnottnulltoftofftoffsettoldtontonlytortordertplacingtprimaryt referencest returningtselectt session_usertsomet symmetricttabletthenttottrailingttruetuniontuniquetusertusingtvariadictwhentwheretwindowtwitht authorizationtbetweentbinarytcrosstcurrent_schematfreezetfulltiliketinnertistisnulltjointlefttliketnaturaltnotnulltoutertovertoverlapstrighttsimilartverboseiiiiiiiiiiiiitBYTEAcBseZdZRS(R|(t__name__t __module__t__visit_name__(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR|7stDOUBLE_PRECISIONcBseZdZRS(R(R}R~R(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR;stINETcBseZdZRS(R(R}R~R(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR?stCIDRcBseZdZRS(R(R}R~R(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRFstMACADDRcBseZdZRS(R(R}R~R(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRMstMONEYcBseZdZdZRS(sCProvide the PostgreSQL MONEY type. .. versionadded:: 1.2 R(R}R~t__doc__R(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRTstOIDcBseZdZdZRS(sCProvide the PostgreSQL OID type. .. versionadded:: 0.9.5 R(R}R~RR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR_stREGCLASScBseZdZdZRS(sHProvide the PostgreSQL REGCLASS type. .. versionadded:: 1.2.7 R(R}R~RR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRjst TIMESTAMPcBseZeddZRS(cCs&tt|jd|||_dS(Nttimezone(tsuperRt__init__t precision(tselfRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRvsN(R}R~tFalsetNoneR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRustTIMEcBseZeddZRS(cCs&tt|jd|||_dS(NR(RRRR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR|sN(R}R~RRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR{stINTERVALcBsVeZdZdZeZdddZedZ e dZ e dZ RS(sPostgreSQL INTERVAL type. The INTERVAL type may not be supported on all DBAPIs. It is known to work on psycopg2 and not pg8000 or zxjdbc. RcCs||_||_dS(s Construct an INTERVAL. :param precision: optional integer precision value :param fields: string fields specifier. allows storage of fields to be limited, such as ``"YEAR"``, ``"MONTH"``, ``"DAY TO HOUR"``, etc. .. versionadded:: 1.2 N(Rtfields(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs cKstd|jS(NR(Rtsecond_precision(tclstintervaltkw((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytadapt_emulated_to_nativescCstjS(N(R tInterval(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_type_affinityscCstjS(N(tdtt timedelta(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt python_typesN( R}R~RRtTruetnativeRRt classmethodRtpropertyRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstBITcBseZdZdedZRS(RcCs.|s|pd|_n ||_||_dS(Ni(tlengthtvarying(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs N(R}R~RRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRsRcBs2eZdZdZedZdZdZRS(s PostgreSQL UUID type. Represents the UUID column type, interpreting data either as natively returned by the DBAPI or as Python uuid objects. The UUID type may not be supported on all DBAPIs. It is known to work on psycopg2 and not pg8000. RcCs.|r!tdkr!tdn||_dS(sConstruct a UUID type. :param as_uuid=False: if True, values will be interpreted as Python uuid objects, converting to/from string via the DBAPI. s=This version of Python does not support the native UUID type.N(t _python_UUIDRtNotImplementedErrortas_uuid(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs  cCs|jrd}|SdSdS(NcSs"|dk rtj|}n|S(N(RRt text_type(tvalue((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytprocesss (RR(RtdialectR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytbind_processors  cCs|jrd}|SdSdS(NcSs|dk rt|}n|S(N(RR(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs (RR(RRtcoltypeR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytresult_processors  (R}R~RRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs    tTSVECTORcBseZdZdZRS(sThe :class:`.postgresql.TSVECTOR` type implements the PostgreSQL text search type TSVECTOR. It can be used to do full text queries on natural language documents. .. versionadded:: 0.9.0 .. seealso:: :ref:`postgresql_match` R(R}R~RR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstENUMcBseZdZeZdZedZd edZ d edZ dZ e dZ e dZe dZe d ZRS( s PostgreSQL ENUM type. This is a subclass of :class:`.types.Enum` which includes support for PG's ``CREATE TYPE`` and ``DROP TYPE``. When the builtin type :class:`.types.Enum` is used and the :paramref:`.Enum.native_enum` flag is left at its default of True, the PostgreSQL backend will use a :class:`.postgresql.ENUM` type as the implementation, so the special create/drop rules will be used. The create/drop behavior of ENUM is necessarily intricate, due to the awkward relationship the ENUM type has in relationship to the parent table, in that it may be "owned" by just a single table, or may be shared among many tables. When using :class:`.types.Enum` or :class:`.postgresql.ENUM` in an "inline" fashion, the ``CREATE TYPE`` and ``DROP TYPE`` is emitted corresponding to when the :meth:`.Table.create` and :meth:`.Table.drop` methods are called:: table = Table('sometable', metadata, Column('some_enum', ENUM('a', 'b', 'c', name='myenum')) ) table.create(engine) # will emit CREATE ENUM and CREATE TABLE table.drop(engine) # will emit DROP TABLE and DROP ENUM To use a common enumerated type between multiple tables, the best practice is to declare the :class:`.types.Enum` or :class:`.postgresql.ENUM` independently, and associate it with the :class:`.MetaData` object itself:: my_enum = ENUM('a', 'b', 'c', name='myenum', metadata=metadata) t1 = Table('sometable_one', metadata, Column('some_enum', myenum) ) t2 = Table('sometable_two', metadata, Column('some_enum', myenum) ) When this pattern is used, care must still be taken at the level of individual table creates. Emitting CREATE TABLE without also specifying ``checkfirst=True`` will still cause issues:: t1.create(engine) # will fail: no such type 'myenum' If we specify ``checkfirst=True``, the individual table-level create operation will check for the ``ENUM`` and create if not exists:: # will check if enum exists, and emit CREATE TYPE if not t1.create(engine, checkfirst=True) When using a metadata-level ENUM type, the type will always be created and dropped if either the metadata-wide create/drop is called:: metadata.create_all(engine) # will emit CREATE TYPE metadata.drop_all(engine) # will emit DROP TYPE The type can also be created and dropped directly:: my_enum.create(engine) my_enum.drop(engine) .. versionchanged:: 1.0.0 The PostgreSQL :class:`.postgresql.ENUM` type now behaves more strictly with regards to CREATE/DROP. A metadata-level ENUM type will only be created and dropped at the metadata level, not the table level, with the exception of ``table.create(checkfirst=True)``. The ``table.drop()`` call will now emit a DROP TYPE for a table-level enumerated type. cOs2|jdt|_tt|j||dS(sConstruct an :class:`~.postgresql.ENUM`. Arguments are the same as that of :class:`.types.Enum`, but also including the following parameters. :param create_type: Defaults to True. Indicates that ``CREATE TYPE`` should be emitted, after optionally checking for the presence of the type, when the parent table is being created; and additionally that ``DROP TYPE`` is called when the table is dropped. When ``False``, no check will be performed and no ``CREATE TYPE`` or ``DROP TYPE`` is emitted, unless :meth:`~.postgresql.ENUM.create` or :meth:`~.postgresql.ENUM.drop` are called directly. Setting to ``False`` is helpful when invoking a creation scheme to a SQL file without access to the actual database - the :meth:`~.postgresql.ENUM.create` and :meth:`~.postgresql.ENUM.drop` methods can be used to emit SQL to a target bind. t create_typeN(tpopRRRRR(RtenumsR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRYscKs|jd|j|jd|j|jd|j|jd|j|jd|j|jdt|jd|j||S(sbProduce a PostgreSQL native :class:`.postgresql.ENUM` from plain :class:`.Enum`. tvalidate_stringstnameRtinherit_schematmetadatat_create_eventstvalues_callable(t setdefaultRRRRRRR(RtimplR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRwscCsS|jjsdS| s9|jj||jd|j rO|jt|ndS(sEmit ``CREATE TYPE`` for this :class:`~.postgresql.ENUM`. If the underlying dialect does not support PostgreSQL CREATE TYPE, no action is taken. :param bind: a connectable :class:`.Engine`, :class:`.Connection`, or similar object to emit SQL. :param checkfirst: if ``True``, a query against the PG catalog will be first performed to see if the type does not exist already before creating. NR(Rtsupports_native_enumthas_typeRRtexecutetCreateEnumType(Rtbindt checkfirst((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR's  cCsR|jjsdS| s8|jj||jd|jrN|jt|ndS(sEmit ``DROP TYPE`` for this :class:`~.postgresql.ENUM`. If the underlying dialect does not support PostgreSQL DROP TYPE, no action is taken. :param bind: a connectable :class:`.Engine`, :class:`.Connection`, or similar object to emit SQL. :param checkfirst: if ``True``, a query against the PG catalog will be first performed to see if the type actually exists before dropping. NR(RRRRRRt DropEnumType(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdrops  cCs|js tSd|kr|d}d|jkrB|jd}nt}|jd<|j|jf|k}|j|j|jf|StSdS(sLook in the 'ddl runner' for 'memos', then note our name in that collection. This to ensure a particular named enum is operated upon only once within any kind of create/drop sequence without relying upon "checkfirst". t _ddl_runnert _pg_enumsN(RRtmemotsetRRtaddR(RRRt ddl_runnertpg_enumstpresent((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_check_for_name_in_memoss   cKsS|s6|j rO|jdt rO|j|| rO|jd|d|ndS(Nt_is_metadata_operationRR(RtgetRRR'(RttargetRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_on_table_creates  cKsM|j rI|jdt rI|j|| rI|jd|d|ndS(NRRR(RRRRR(RRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_on_table_drops cKs/|j||s+|jd|d|ndS(NRR(RR'(RRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_on_metadata_createscKs/|j||s+|jd|d|ndS(NRR(RR(RRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_on_metadata_dropsN(R}R~RRt native_enumRRRRR'RRRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR sL    tintegertbiginttsmallintscharacter varyingt characters"char"Rttexttnumerictfloattrealtinettcidrtuuidtbits bit varyingtmacaddrtmoneytoidtregclasssdouble precisiont timestampstimestamp with time zonestimestamp without time zonestime with time zonestime without time zonetdatettimetbyteatbooleanRttsvectort PGCompilercBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZRS(cKsd|j||S(Ns ARRAY[%s](tvisit_clauselist(RtelementR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_arrayscKs,d|j|j||j|j|fS(Ns%s:%s(Rtstarttstop(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_slicescKst|d<|j|d|S(Nteager_groupings -> (Rt_generate_generic_binary(RRhtoperatorR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_json_getitem_op_binarys cKst|d<|j|d|S(NRs #> (RR(RRhRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt!visit_json_path_getitem_op_binarys cKs,d|j|j||j|j|fS(Ns%s[%s](RRrRy(RRhRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_getitem_binary scKs,d|j|j||j|j|fS(Ns%s ORDER BY %s(RRtorder_by(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_aggregate_order_by&scKsd|jkrc|j|jdtj}|rcd|j|j|||j|j|fSnd|j|j||j|j|fS(Ntpostgresql_regconfigs%s @@ to_tsquery(%s, %s)s%s @@ to_tsquery(%s)(t modifierstrender_literal_valueR t STRINGTYPERRrRy(RRhRRt regconfig((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_match_op_binary,scKsd|jjdd}d|j|j||j|j|f|r_d|j|tjndS(Ntescapes %s ILIKE %ss ESCAPE t( RRRRRrRyRR R(RRhRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_ilike_op_binary<s cKsd|jjdd}d|j|j||j|j|f|r_d|j|tjndS(NRs%s NOT ILIKE %ss ESCAPE R( RRRRRrRyRR R(RRhRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_notilike_op_binaryHs cs0ddjfd|p$tgDfS(NsSELECT %s WHERE 1!=1s, c3s:|]0}djjj|jr*tn|VqdS(sCAST(NULL AS %s)N(Rt type_compilerRt_isnullR(t.0ttype_(R(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys Ys(RqR(Rt element_types((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_empty_set_exprSs cCs@tt|j||}|jjr<|jdd}n|S(Ns\s\\(RRRRt_backslash_escapestreplace(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRas cKsd|jj|S(Ns nextval('%s')(tpreparertformat_sequence(RtseqR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_sequencehscKsd}|jdk r5|d|j|j|7}n|jdk r|jdkr`|d7}n|d|j|j|7}n|S(NRs LIMIT s LIMIT ALLs OFFSET (t _limit_clauseRRt_offset_clause(RRTRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt limit_clauseks   cCs0|jdkr(tjd|nd|S(NtONLYsUnrecognized hint: %rsONLY (tupperRt CompileError(RtsqltextRXthinttiscrud((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytformat_from_hint_textuscKs|jtk r|jtkr"dSt|jttfrqddjg|jD]}|j||^qMdSd|j|j|dSndSdS(Ns DISTINCT s DISTINCT ON (s, s) R(t _distinctRRt isinstancetlistttupleRqR(RRTRtcol((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_select_precolumnszs7c s|jjr*|jjr!d}qEd}n|jjr?d}nd}|jjrtj}x*|jjD]}|jtj|qjW|ddj fd|D7}n|jj r|d7}n|jj r|d 7}n|S( Ns FOR KEY SHAREs FOR SHAREs FOR NO KEY UPDATEs FOR UPDATEs OF s, c3s-|]#}j|dtdtVqdS(tashintt use_schemaN(RRR(RRX(RR(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys ss NOWAITs SKIP LOCKED( t_for_update_argtreadt key_shareRHRt OrderedSettupdatetsql_utiltsurface_selectables_onlyRqtnowaitt skip_locked(RRTRttmpttablestc((RRsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytfor_update_clauses&             cCsHgtj|D]!}|jd|tti^q}ddj|S(Ns RETURNING s, (R t_select_iterablest_label_select_columnRRRRq(Rtstmttreturning_colsR,tcolumns((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytreturning_clauses4cKs|j|jjd|}|j|jjd|}t|jjdkr}|j|jjd|}d|||fSd||fSdS(NiiisSUBSTRING(%s FROM %s FOR %s)sSUBSTRING(%s FROM %s)(Rtclausestlen(RtfuncRtsRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_substring_funcs c s|jdk rd|j}nv|jdk rddjfd|jD}|jdk r|dj|jdtdt7}qnd}|S( NsON CONSTRAINT %ss(%s)s, c3sN|]D}t|tjr-jj|nj|dtdtVqdS(t include_tableR N(RRt string_typesR tquoteRR(RR,(R(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys ss WHERE %sR9R R(tconstraint_targetRtinferred_target_elementsRqtinferred_target_whereclauseRR(RtclauseRt target_text((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_on_conflict_targets    cKs(|j||}|r d|SdSdS(NsON CONFLICT %s DO NOTHINGsON CONFLICT DO NOTHING(RA(Rt on_conflictRR@((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_on_conflict_do_nothingscKsH|}|j||}g}t|j}|jdd}|jj}x|D]} | j} | |krQ|j| } tj | rtj d| d| j } n9t | tj r| j jr| j} | j | _ n|j| jdt} |jj| } |jd| | fqQqQW|rtjd|jjjdjd|Dfx|jD]z\}}t |tjr|jj|n|j|dt} |jtj|dt} |jd| | fqrWndj|}|jdk r:|d |j|jd tdt7}nd ||fS( Nit selectableRR s%s = %ssFAdditional column names not matching any column keys in table '%s': %ss, css|]}d|VqdS(s'%s'N((RR,((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys ss WHERE %sR9sON CONFLICT %s DO UPDATE SET %s( RAtdicttupdate_values_to_settstackRXR,tkeyRRt _is_literalt BindParameterRttypeRRt_cloneRt self_groupRR R;tappendRtwarnt statementRRqtitemsR:t_literal_as_bindstupdate_whereclauseR(RRBRR?R@taction_set_opstset_parameterstinsert_statementtcolsR,tcol_keyRt value_texttkey_texttktvt action_text((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_on_conflict_do_updatesF       $ c s'ddjfd|DS(NsFROM s, c3s-|]#}|jdtdVqdS(tasfromt fromhintsN(t_compiler_dispatchR(Rtt(t from_hintsRR(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys !s(Rq(Rt update_stmtt from_tablet extra_fromsRcR((RcRRsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytupdate_from_clauses c s'ddjfd|DS(s9Render the DELETE .. USING clause specific to PostgreSQL.sUSING s, c3s-|]#}|jdtdVqdS(R_R`N(RaR(RRb(RcRR(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys *s(Rq(Rt delete_stmtReRfRcR((RcRRsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdelete_extra_from_clause%s (R}R~RRRRRRRRRRRRRRRR-R3R8RARCR^RgRi(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs.               = t PGDDLCompilercBsPeZdZdZdZdZdZdZdZdZ RS(cKsf|jj|}|jj|j}t|tjrE|j}n|j r||j j kr|jj st|tj  r|jdkst|jtjr|jjrt|tjr|d7}qLt|tj r|d7}qL|d7}nR|d|jjj|jd|7}|j|}|dk rL|d|7}n|jsb|d7}n|S(Ns BIGSERIALs SMALLSERIALs SERIALt ttype_expressions DEFAULT s NOT NULL(R t format_columnRKt dialect_implRRR t TypeDecoratorRt primary_keyRXt_autoincrement_columntsupports_smallserialt SmallIntegerRRRtSequencetoptionalt BigIntegerRRtget_column_default_stringtnullable(RR%tkwargstcolspect impl_typeR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_column_specification0s0          cCsd|jj|jS(NsCOMMENT ON TABLE %s IS NULL(R t format_tableR(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_drop_table_commentXs cs?|j}djj|djfd|jDfS(NsCREATE TYPE %s AS ENUM (%s)s, c3s0|]&}jjtj|dtVqdS(t literal_bindsN(t sql_compilerRRtliteralR(Rte(R(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys cs(RR t format_typeRqR(RR'R((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_create_enum_type]s   cCs|j}d|jj|S(Ns DROP TYPE %s(RR R(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_drop_enum_typehs c CsZ|j}|j}|j|d}|jr;|d7}n|d7}|jjrx|jdd}|rx|d7}qxn|d|j|dt|j |j f7}|jdd }|r|d |jj |t j 7}n|jdd }|d d jg|jD]u}|jjt|tjs8|jn|dtdtt|dry|j|kryd||jnd^q 7}|jdd} | r|dd jg| jD]} d| ^q7}n|jdd} | r |d|j| 7}n|jdd} | dk rV|jj| dtdt} |d| 7}n|S(NsCREATE sUNIQUE sINDEX t postgresqlt concurrentlys CONCURRENTLY s %s ON %s tinclude_schemaR`s USING %s topss(%s)s, R9RRHRkRRes WITH (%s)s%s = %st tablespaces TABLESPACE %sRcs WHERE (R Rt_verify_index_tableR^Rt#_supports_create_index_concurrentlytdialect_optionst_prepared_index_nameRR}RXtvalidate_sql_phraset IDX_USINGtlowerRqt expressionsRRRR t ColumnClauseRMRthasattrRHRQR;R(RR'R tindexRRR`Rtexprt withclausetstorage_parameterttablespace_namet whereclausetwhere_compiled((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_create_indexmsN         (  cCs_|j}d}|jjrB|jdd}|rB|d7}qBn||j|dt7}|S(Ns DROP INDEX RRs CONCURRENTLY R(RRt!_supports_drop_index_concurrentlyRRR(RRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_drop_indexs  cKsd}|jdk r2|d|jj|7}ng}xJ|jD]?\}}}t|d<|jd|jj|||fqBW|d|jj |j t j dj |f7}|jdk r|d|jj|jdt7}n||j|7}|S( NRsCONSTRAINT %s R9s %s WITH %ssEXCLUDE USING %s (%s)s, s WHERE (%s)R(RRR tformat_constraintt _render_exprsRRNRRRR`RRRqRcRtdefine_constraint_deferrability(RR&RRRRRtop((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_exclude_constraints$ $ cs]g}|jd}|jd}|dk rt|ttfsO|f}n|jddjfd|Ddn|dr|jd|dn|d tkr|jd n |d t kr|jd n|d r|d j d dj }|jd|n|drP|d}|jdj j |ndj|S(NRtinheritss INHERITS ( s, c3s!|]}jj|VqdS(N(R R;(RR(R(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys ss )t partition_bys PARTITION BY %st with_oidss WITH OIDSs WITHOUT OIDSt on_committ_Rks ON COMMIT %sRs TABLESPACE %sR(RRRRRRRNRqRRR RR R;(RRXt table_optstpg_optsRton_commit_optionsR((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytpost_create_tables,   +    ( R}R~R|R~RRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRj/s (   I tPGTypeCompilercBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZRS(cKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_TSVECTORscKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_INETscKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_CIDRscKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_MACADDR scKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_MONEY scKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_OIDscKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_REGCLASSscKs#|js dSdi|jd6SdS(NRsFLOAT(%(precision)s)R(R(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_FLOATs cKsdS(NsDOUBLE PRECISION((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_DOUBLE_PRECISIONscKsdS(NR ((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_BIGINTscKsdS(NtHSTORE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_HSTORE!scKsdS(NtJSON((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_JSON$scKsdS(NtJSONB((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_JSONB'scKsdS(Nt INT4RANGE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_INT4RANGE*scKsdS(Nt INT8RANGE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_INT8RANGE-scKsdS(NtNUMRANGE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_NUMRANGE0scKsdS(Nt DATERANGE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_DATERANGE3scKsdS(NtTSRANGE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_TSRANGE6scKsdS(Nt TSTZRANGE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_TSTZRANGE9scKs|j||S(N(tvisit_TIMESTAMP(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_datetime<scKsD|j s|jj r0tt|j||S|j||SdS(N(RRRRRt visit_enumt visit_ENUM(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR?scKs|jjj|S(N(Rtidentifier_preparerR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyREscKsFdt|dddk r(d|jnd|jr:dp=ddfS(NsTIMESTAMP%s %sRs(%d)RtWITHtWITHOUTs TIME ZONE(tgetattrRRR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRHs%cKsFdt|dddk r(d|jnd|jr:dp=ddfS(Ns TIME%s %sRs(%d)RRRs TIME ZONE(RRRR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_TIMEPs%cKsPd}|jdk r)|d|j7}n|jdk rL|d|j7}n|S(NRRks (%d)(RRR(RRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_INTERVALXs cKsF|jr5d}|jdk rB|d|j7}qBn d|j}|S(Ns BIT VARYINGs(%d)sBIT(%d)(RRR(RRRtcompiled((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_BIT`s   cKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_UUIDiscKs|j||S(N(t visit_BYTEA(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_large_binarylscKsdS(NR|((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRoscKsK|j|j}tjddd|jdk r9|jnd|ddS(Ns((?: COLLATE.*)?)$s%s\1s[]itcount(Rt item_typetretsubt dimensionsR(RRRRn((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_ARRAYrs( R}R~RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs<                            tPGIdentifierPreparercBs#eZeZdZedZRS(cCs9|d|jkr5|dd!j|j|j}n|S(Niii(t initial_quoteR tescape_to_quotet escape_quote(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_unquote_identifiers cCsv|jstjdn|j|j}|j|}|j rr|rr|dk rr|j|d|}n|S(Ns%PostgreSQL ENUM type requires a name.t.(RRRR;tschema_for_objectt omit_schemaRt quote_schema(RRR Rteffective_schema((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs   (R}R~tRESERVED_WORDStreserved_wordsRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs t PGInspectorcBsDeZdZddZddZddZdddZRS( cCstjj||dS(N(Rt InspectorR(Rtconn((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRscCs"|jj|j||d|jS(s(Return the OID for the given table name.t info_cache(Rt get_table_oidRR(Rt table_nameR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs cCs%|p |j}|jj|j|S(sKReturn a list of ENUM objects. Each member is a dictionary containing these fields: * name - name of the enum * schema - the schema name for the enum. * visible - boolean, whether or not this enum is visible in the default search path. * labels - a list of string labels that apply to the enum. :param schema: schema name. If None, the default schema (typically 'public') is used. May also be set to '*' to indicate load enums for all schemas. .. versionadded:: 1.0.0 (tdefault_schema_nameRt _load_enumsR(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt get_enumsscCs%|p |j}|jj|j|S(sReturn a list of FOREIGN TABLE names. Behavior is similar to that of :meth:`.Inspector.get_table_names`, except that the list is limited to those tables that report a ``relkind`` value of ``f``. .. versionadded:: 1.0.0 (RRt_get_foreign_table_namesR(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_foreign_table_namess tplaint materializedcCs%|jj|j|d|jd|S(sReturn all view names in `schema`. :param schema: Optional, retrieve names from a non-default schema. For special quoting, use :class:`.quoted_name`. :param include: specify which types of views to return. Passed as a string value (for a single type) or a tuple (for any number of types). Defaults to ``('plain', 'materialized')``. .. versionadded:: 1.1 Rtinclude(Rtget_view_namesRR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs N(RR(R}R~RRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs     RcBseZdZRS(tcreate_enum_type(R}R~R(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRsRcBseZdZRS(tdrop_enum_type(R}R~R(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstPGExecutionContextcBs#eZdZdZdZRS(cCs#|jd|jjj||S(Nsselect nextval('%s')(t_execute_scalarRRR (RR R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt fire_sequencescCs|jr~||jjkr~|jrM|jjrM|jd|jj|jS|jdkst|jj r~|jj r~y |j }Wnt k r|jj}|j}|ddtddt|!}|ddtddt|!}d||f}||_ }nX|jdk r6|jj|j}nd}|dk r[d||f}n d|f}|j||jSntt|j|S(Ns select %siis %s_%s_seqsselect nextval('"%s"."%s"')sselect nextval('"%s"')(RpRXRqtserver_defaultt has_argumentRtargRKRRt is_sequenceRut_postgresql_seq_nametAttributeErrorRtmaxR5t connectionRRRtget_insert_default(RR%tseq_namettabRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs4    $$    cCs tj|S(N(tAUTOCOMMIT_REGEXPtmatch(RRP((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytshould_autocommit_text s(R}R~RRR (((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs .t PGDialectcBs&eZdZeZdZeZeZeZeZ eZ eZ eZ e ZeZeZe ZeZdZeZeZeZeZeZeZeZe Z!d6Z#e$j%ie d6d6d6id6e d6id6d6d6fe$j&ie d 6d6d6d6d 6d6d 6d6d 6d6d 6fgZ'd7Z(eZ)eZ*eZ+d6d6d6dZ,dZ-dZ.e/ddddgZ0dZ1dZ2dZ3dZ4ee dZ5ee dZ6dZ7dZ8dZ9d6dZ:d6d Z;d6d!Z<d"Z=e>j?d6d#Z@e>j?d$ZAe>j?d6d%ZBe>j?d6d&ZCe>j?d6d8d)ZDe>j?d6d*ZEe>j?d6d+ZFd,ZGe>j?d6d-ZHe>j?d6e d.ZId/ZJe>j?d0ZKe>j?d6d1ZLe>j?d6d2ZMe>j?d6d3ZNd6d4ZOd5ZPRS(9Ri?tpyformatR`RcRRReRtignore_search_pathRRRRtpostgresql_ignore_search_pathcKs2tjj||||_||_||_dS(N(RtDefaultDialectRtisolation_levelt_json_deserializert_json_serializer(RRtjson_serializertjson_deserializerRy((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRa s  cCstt|j||jdko7|jjdt|_|jd k|_|js|j j |_ |j j t j d|j j tdn|jd k|_|jd kp|jddk|_|jd k|_|jd k|_dS(Niitimplicit_returningii s show standard_conforming_stringsRI(ii(ii(i i(ii(ii(i i(RR t initializetserver_version_infot__dict__RRRRtcolspecstcopyRR tEnumRRRrtscalarR RR(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRm s"  cs*jdk r"fd}|SdSdS(Ncsj|jdS(N(tset_isolation_levelR(R(R(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytconnect s(RR(RR ((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt on_connect st SERIALIZABLEsREAD UNCOMMITTEDsREAD COMMITTEDsREPEATABLE READcCs|jdd}||jkrOtjd||jdj|jfn|j}|jd||jd|jdS(NRRksLInvalid value '%s' for isolation_level. Valid isolation levels for %s are %ss, s=SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL %stCOMMIT( R t_isolation_lookupRt ArgumentErrorRRqtcursorRtclose(RRtlevelR&((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR s%  cCs=|j}|jd|jd}|j|jS(Ns show transaction isolation leveli(R&RtfetchoneR'R(RRR&tval((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_isolation_level s    cCs|j|jdS(N(tdo_beginR(RRtxid((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdo_begin_twophase scCs|jd|dS(NsPREPARE TRANSACTION '%s'(R(RRR-((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdo_prepare_twophase scCsa|rM|r|jdn|jd||jd|j|jn|j|jdS(NtROLLBACKsROLLBACK PREPARED '%s'tBEGIN(Rt do_rollbackR(RRR-t is_preparedtrecover((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdo_rollback_twophase s cCsa|rM|r|jdn|jd||jd|j|jn|j|jdS(NR0sCOMMIT PREPARED '%s'R1(RR2Rt do_commit(RRR-R3R4((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdo_commit_twophase s cCs3|jtjd}g|D]}|d^qS(Ns!SELECT gid FROM pg_prepared_xactsi(RRR(RRt resultsettrow((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdo_recover_twophase scCs |jdS(Nsselect current_schema()(R(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_get_default_schema_name scCs[d}|jtj|jtjdtj|jdtj }t |j S(Ns=select nspname from pg_namespace where lower(nspname)=:schemaRR( RRRt bindparamst bindparamRRRR tUnicodetbooltfirst(RRRtqueryR&((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt has_schema scCs|dkrN|jtjdjtjdtj|dtj }n`|jtjdjtjdtj|dtj tjdtj|dtj }t |j S(Nsselect relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where pg_catalog.pg_table_is_visible(c.oid) and relname=:nameRRstselect relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where n.nspname=:schema and relname=:nameR( RRRRR<R=RRR R>R?R@(RRRRR&((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt has_table s(    cCs|dkrN|jtjdjtjdtj|dtj }n`|jtjdjtjdtj|dtj tjdtj|dtj }t |j S(NsSELECT relname FROM pg_class c join pg_namespace n on n.oid=c.relnamespace where relkind='S' and n.nspname=current_schema() and relname=:nameRRsSELECT relname FROM pg_class c join pg_namespace n on n.oid=c.relnamespace where relkind='S' and n.nspname=:schema and relname=:nameR( RRRRR<R=RRR R>R?R@(RRt sequence_nameRR&((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt has_sequence s(    cCs|dk r$d}tj|}nd}tj|}|jtjdtj|dtj}|dk r|jtjdtj|dtj}n|j |}t |j S(Ns  SELECT EXISTS ( SELECT * FROM pg_catalog.pg_type t, pg_catalog.pg_namespace n WHERE t.typnamespace = n.oid AND t.typname = :typname AND n.nspname = :nspname ) s SELECT EXISTS ( SELECT * FROM pg_catalog.pg_type t WHERE t.typname = :typname AND pg_type_is_visible(t.oid) ) ttypnameRtnspname( RRRR<R=RRR R>RR?R(RRt type_nameRRAR&((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR< s ! $cCs~|jdj}tjd|}|s@td|ntg|jdddD]}|dk rYt|^qYS(Nsselect version()sQ.*(?:PostgreSQL|EnterpriseDB) (\d+)\.?(\d+)?(?:\.(\d+))?(?:\.\d+)?(?:devel|beta)?s,Could not determine version from string '%s'iii( RRRR tAssertionErrorRR;Rtint(RRR\tmtx((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_get_server_version_info^ s c Ksd}|dk rd}nd}d|}tj|}|dk rXtj|}ntj|jdtj}|jdtj }|r|jtj ddtj}n|j |d|d|} | j }|dkrt j|n|S( sFetch the oid for schema.table_name. Several reflection methods require the table oid. The idea for using this method is that it can be fetched one time and cached for subsequent calls. sn.nspname = :schemas%pg_catalog.pg_table_is_visible(c.oid)s  SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE (%s) AND c.relname = :table_name AND c.relkind in ('r', 'v', 'm', 'f', 'p') RRRRN(RRRRRR<R R>R2tIntegerR=RRRtNoSuchTableError( RRRRRt table_oidtschema_where_clauseRAR7R,((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRk s$     $  cKsA|jtjdjdtj}g|D]\}|^q.S(NsOSELECT nspname FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' ORDER BY nspnameRG(RRRR2R R>(RRRtresultR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_schema_names s  cKs\|jtjdjdtjd|dk r6|n|j}g|D]\}|^qIS(NsSELECT c.relname FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = :schema AND c.relkind in ('r', 'p')trelnameR(RRRR2R R>RR(RRRRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_table_names s   cKs\|jtjdjdtjd|dk r6|n|j}g|D]\}|^qIS(Ns|SELECT c.relname FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = :schema AND c.relkind = 'f'RTR(RRRR2R R>RR(RRRRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR s   RRc Ksidd6dd6}y*gtj|D]}||^q'}Wn$tk rdtd|fnX|sztdn|jtjddjd |Djd t j d |dk r|n|j }g|D]\} | ^qS( NR\RRKRs_include %r unknown, needs to be a sequence containing one or both of 'plain' and 'materialized'sZempty include, needs to be a sequence containing one or both of 'plain' and 'materialized's~SELECT c.relname FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = :schema AND c.relkind IN (%s)s, css|]}d|VqdS(s'%s'N((Rtelem((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys sRTR( Rtto_listtKeyErrort ValueErrorRRRRqR2R R>RR( RRRRRt include_kindtitkindsRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR s"*    cKsL|jtjdjdtjd|dk r6|n|jd|}|S(NsSELECT pg_get_viewdef(c.oid) view_def FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = :schema AND c.relname = :view_name AND c.relkind IN ('v', 'm')tview_defRt view_name(RRRR2R R>RR(RRR^RRR]((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_view_definition s   c Ks"|j|||d|jd}d}tj|jtjddtjjdtj dtj }|j |d|}|j } |j |} t d|j|dd D} g} xT| D]L\} }}}}}}|j| |||| | ||}| j|qW| S( NRs SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod), (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid) FROM pg_catalog.pg_attrdef d WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) AS DEFAULT, a.attnotnull, a.attnum, a.attrelid as table_oid, pgd.description as comment FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_description pgd ON ( pgd.objoid = a.attrelid AND pgd.objsubid = a.attnum) WHERE a.attrelid = :table_oid AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum RPRtattnameRcssF|]<}|dr&|df|fn|d|df|fVqdS(tvisibleRRN((Rtrec((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys  sRt*(RRRRR<R=R RNR2R>Rtfetchallt _load_domainsRERt_get_column_infoRN(RRRRRRPtSQL_COLSR7R,trowstdomainsRR2RRtdefault_Rutattnumtcommentt column_info((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt get_columns s4  c  Csd} tjdd|} | | \} } ttj| } | } tjd|}|rv|jd}ntjd|}|r|jdrttjd|jd}nd*}i}| dkr|r|jd \}}t|t|f}qld+}nT| d kr-d,}n?| d krBd-}n*| d.krzt |d<|rqt||d c Ks|j|||d|jd}|jdkrLd|jdd}nd}tj|jdtj}|j |d |}g|j D]} | d ^q} d } tj| jd tj}|j |d |}|j } i| d 6| d6S(NRiisq SELECT a.attname FROM pg_class t join pg_index ix on t.oid = ix.indrelid join pg_attribute a on t.oid=a.attrelid AND %s WHERE t.oid = :table_oid and ix.indisprimary = 't' ORDER BY a.attnum sa.attnums ix.indkeys SELECT a.attname FROM pg_attribute a JOIN ( SELECT unnest(ix.indkey) attnum, generate_subscripts(ix.indkey, 1) ord FROM pg_index ix WHERE ix.indrelid = :table_oid AND ix.indisprimary ) k ON a.attnum=k.attnum WHERE a.attrelid = :table_oid ORDER BY k.ord R`RPis SELECT conname FROM pg_catalog.pg_constraint r WHERE r.conrelid = :table_oid AND r.contype = 'p' ORDER BY 1 tconnametconstrained_columnsR(ii( RRRt _pg_index_anyRRR2R R>RRdR( RRRRRRPtPK_SQLRbR,trRWt PK_CONS_SQLR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_pk_constraint s # cKs?|j}|j|||d|jd}d}tjd} tj|jdtj dtj } |j | d|} g} x| j D]\} }}tj | |j }|\ }}}}}}}}}}}}}|dk r |dkrtnt}ngtjd|D]}|j|^q}|ra||jkrX|}q|}n9|ry|j|}n!|dk r||kr|}n|j|}gtjd |D]}|j|^q}i| d 6|d 6|d 6|d 6|d6i|d6|d6|d6|d6|d6d6}| j|qW| S(NRs SELECT r.conname, pg_catalog.pg_get_constraintdef(r.oid, true) as condef, n.nspname as conschema FROM pg_catalog.pg_constraint r, pg_namespace n, pg_class c WHERE r.conrelid = :table AND r.contype = 'f' AND c.oid = confrelid AND n.oid = c.relnamespace ORDER BY 1 s/FOREIGN KEY \((.*?)\) REFERENCES (?:(.*?)\.)?(.*?)\((.*?)\)[\s]?(MATCH (FULL|PARTIAL|SIMPLE)+)?[\s]?(ON UPDATE (CASCADE|RESTRICT|NO ACTION|SET NULL|SET DEFAULT)+)?[\s]?(ON DELETE (CASCADE|RESTRICT|NO ACTION|SET NULL|SET DEFAULT)+)?[\s]?(DEFERRABLE|NOT DEFERRABLE)?[\s]?(INITIALLY (DEFERRED|IMMEDIATE)+)?RtcondefRXt DEFERRABLEs\s*,\s*s\s*,\sRRtreferred_schematreferred_tabletreferred_columnstonupdatetondeleteR.R>R toptions(RRRRtcompileRRR2R R>RRdRwtgroupsRRRRxRRRN(RRRRRRR RPtFK_SQLtFK_REGEXRbR,tfkeysRRt conschemaRKRRRRRR RRR.R>RLtfkey_d((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_foreign_keys sT  - +   +csN|jd kr<ddjfdtddDSdfSdS( Niis(%s)s OR c3s"|]}d|fVqdS(s %s[%d] = %sN((Rtind(Rt compare_to(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys h sii s %s = ANY(%s)(ii(RRqtrange(RRR((RRsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR_ s $c# s9|j|||d|jd}|jd)krd|jd*krKdnd|jd+krcdnd |jd,kr{d nd |jd d f}nd}tj|jdtjdtj}|j |d|}t d} d} x.|j D] } | \ } } }}}}}}}}}|rZ| | krNt jd| n| } qn|r| | k rt jd| | } n| | k}| | }|dk r||d| Rs;Skipped unsupported reflection of expression-based index %ss7Predicate of partial index %s ignored during reflectionRWRHiR/t nullslastt nullsfirsttsortingR^tduplicates_constraintt=RtbtreetamnameRt column_namesc3s1|]'\}}dd||fVqdS(RWRHN((RR[R(tidx(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys  stcolumn_sortingRtpostgresql_withtpostgresql_using(ii(ii(ii(ii((R/(R(R(RRRRRRR2R R>RRRRdRRORxRJtstript enumerateRERQRRN(#RRRRRRPtIDX_SQLRbR,tindexest sv_idx_nameR9tidx_nameR^RtprdRtcol_numtconrelidtidx_keyt idx_optionRRthas_idxRR[Rtcol_idxt col_flagst col_sortingtoptionRRRR[tentry((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt get_indexesm s '      /         , )     cKs|j|||d|jd}d}tj|jdtj}|j|d|}td} xB|j D]4} | | j } | j | d<| j | d| j RRRdRRHRRRQ(RRRRRRPt UNIQUE_SQLRbR,tuniquesR9tucRR[((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_unique_constraints& s  cKsY|j|||d|jd}d}|jtj|d|}i|jd6S(NRs SELECT pgd.description as table_comment FROM pg_catalog.pg_description pgd WHERE pgd.objsubid = 0 AND pgd.objoid = :table_oid RPR(RRRRRR(RRRRRRPt COMMENT_SQLR,((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_table_commentL s  c Ks|j|||d|jd}d}|jtj|d|}d}g|jD]&\} } i| d6|| d6^q^S(NRs SELECT cons.conname as name, pg_get_constraintdef(cons.oid) as src FROM pg_catalog.pg_constraint cons WHERE cons.conrelid = :table_oid AND cons.contype = 'c' RPcSs:tjd|}|s-tjd|dS|jdS(Ns^CHECK *\(\((.+)\)\)$s)Could not parse CHECK constraint text: %rRi(RR RROR;(tsrcRK((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt match_consu s RR(RRRRRRd( RRRRRRPt CHECK_SQLR,RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_check_constraints_ s  c Csj|p |j}|jsiSd}|dkr;|d7}n|d7}tj|jdtjdtj}|dkr|jd|}n|j|}g}i}x|j D]}|d|df} | |kr|| d j |dqi|dd6|dd6|d d 6gd 6|| <} |ddk rU| d j |dn|j | qW|S( Ns SELECT t.typname as "name", -- no enum defaults in 8.4 at least -- t.typdefault as "default", pg_catalog.pg_type_is_visible(t.oid) as "visible", n.nspname as "schema", e.enumlabel as "label" FROM pg_catalog.pg_type t LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace LEFT JOIN pg_catalog.pg_enum e ON t.oid = e.enumtypid WHERE t.typtype = 'e' RcsAND n.nspname = :schema s ORDER BY "schema", "name", e.oidR`tlabelRRRsRa( RRRRR2R R>R<RRdRNR( RRRt SQL_ENUMSR7R,Rt enum_by_nameRRHtenum_rec((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR s6         c Csd}tj|jdtj}|j|}i}x|jD]z}tjd|dj d}|dr|df}n|d|df}i|d6|d d 6|d d 6||RRdRRwR;( RRt SQL_DOMAINSR7R,RiRRpRH((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRe s   N(R(RR(QR}R~RRtsupports_altertmax_identifier_lengthtsupports_sane_rowcountRtsupports_native_booleanRrtsupports_sequencestsequences_optionalt"preexecute_autoincrement_sequencesRtpostfetch_lastrowidtsupports_commentstsupports_default_valuestsupports_empty_inserttsupports_multivalues_inserttdefault_paramstyleR{RRtstatement_compilerRjt ddl_compilerRRRR Rtexecution_ctx_clsRt inspectorRRRtIndextTabletconstruct_argumentstreflection_optionsR RRRRR!RR$RR+R.R/R5R7R:R;RBRCRERRMRtcacheRRSRURRR_RnRfRRRRRRRRRe(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR # s             & & " '    D 2h $! 4(]Rt collectionsRtdatetimeRRRRRRRtengineRRRRR R R&ttypesR R R RRRRRRRRRRRt ImportErrorRRRzRtUNICODER RRt_DECIMAL_TYPESt _FLOAT_TYPESt _INT_TYPESt LargeBinaryR|tFloatRt TypeEngineRtPGInetRtPGCidrRt PGMacAddrRRRRRtNativeForEmulatedt_AbstractIntervalRt PGIntervalRtPGBittPGUuidRRRRRtStringR{t SQLCompilerRt DDLCompilerRjtGenericTypeCompilerRtIdentifierPreparerRRRt_CreateDropBaseRRtDefaultExecutionContextRRR (((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyts         ' 8   "@<