PK���ȼRY��������€��� �v3.phpUT �øŽg‰gñ“gux �õ��õ��½T]kÛ0}߯pEhìâÙM7X‰çv%”v0֐µ{)Aå:6S$!ÉMJèߕ?R÷!>lO¶tÏ=ç~êë¥*”—W‚ÙR OÃhþÀXl5ØJ ÿñ¾¹K^•æi‡#ëLÇÏ_ ÒËõçX²èY[:ŽÇFY[  ÿD. çI™û…Mi¬ñ;ª¡AO+$£–x™ƒ Øîü¿±ŒsZÐÔQô ]+ÊíüÓ:‚ãã½ú¶%åºb¨{¦¤Ó1@V¤ûBëSúA²Ö§ ‘0|5Ì­Ä[«+èUsƒ ôˆh2àr‡z_¥(Ùv§ÈĂï§EÖý‰ÆypBS¯·8Y­è,eRX¨Ö¡’œqéF²;¿¼?Ø?Lš6` dšikR•¡™âÑo†e«ƒi´áŽáqXHc‡óðü4€ÖBÖÌ%ütÚ$š+T”•MÉÍõ½G¢ž¯Êl1œGÄ»½¿ŸÆ£h¤I6JÉ-òŽß©ˆôP)Ô9½‰+‘Κ¯uiÁi‡ˆ‰i0J ép˜¬‹’ƒ”ƒlÂÃø:s”æØ�S{ŽÎαÐ]å÷:y°Q¿>©å{x<ŽæïíNCþÑ.Mf?¨«2ý}=ûõýî'=£§ÿu•Ü(—¾IIa­"éþ@¶�¿ä9?^-qìÇÞôvŠeÈc ðlacã®xèÄ'®âd¶ çˆSEæódP/ÍÆv{Ô)Ó ?>…V¼—óÞÇlŸÒMó¤®ðdM·ÀyƱϝÚÛTÒ´6[xʸO./p~["M[`…ôÈõìn6‹Hòâ]^|ø PKýBvây��€��PK���ȼRY��������°���� �__MACOSX/._v3.phpUT �øŽg‰gþ“gux �õ��õ��c`cg`b`ðMLVðVˆP€'qƒøˆŽ!!AP&HÇ %PDF-1.7 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R /F2 9 0 R >> >> /MediaBox [0.000 0.000 595.280 841.890] >> endobj 4 0 obj [/PDF /Text ] endobj 5 0 obj << /Producer (���d�o�m�p�d�f� �2�.�0�.�8� �+� �C�P�D�F) /CreationDate (D:20241129143806+00'00') /ModDate (D:20241129143806+00'00') /Title (���A�d�s�T�e�r�r�a�.�c�o�m� �i�n�v�o�i�c�e) >> endobj 6 0 obj << /Type /Page /MediaBox [0.000 0.000 595.280 841.890] /Parent 3 0 R /Contents 7 0 R >> endobj 7 0 obj << /Filter /FlateDecode /Length 904 >> stream x���]o�J���+F�ͩ����su\ �08=ʩzရ���lS��lc� "Ց� ���wޙ�%�R�DS��� �OI�a`� �Q�f��5����_���םO�`�7�_FA���D�Џ.j�a=�j����>��n���R+�P��l�rH�{0��w��0��=W�2D ����G���I�>�_B3ed�H�yJ�G>/��ywy�fk��%�$�2.��d_�h����&)b0��"[\B��*_.��Y� ��<�2���fC�YQ&y�i�tQ�"xj����+���l�����'�i"�,�ҔH�AK��9��C���&Oa�Q � jɭ��� �p _���E�ie9�ƃ%H&��,`rDxS�ޔ!�(�X!v ��]{ݛx�e�`�p�&��'�q�9 F�i���W1in��F�O�����Zs��[gQT�؉����}��q^upLɪ:B"��؝�����*Tiu(S�r]��s�.��s9n�N!K!L�M�?�*[��N�8��c��ۯ�b�� ��� �YZ���SR3�n�����lPN��P�;��^�]�!'�z-���ӊ���/��껣��4�l(M�E�QL��X ��~���G��M|�����*��~�;/=N4�-|y�`�i�\�e�T�<���L��G}�"В�J^���q��"X�?(V�ߣXۆ{��H[����P�� �c���kc�Z�9v�����? �a��R�h|��^�k�D4W���?Iӊ�]<��4�)$wdat���~�����������|�L��x�p|N�*��E� �/4�Qpi�x.>��d����,M�y|4^�Ż��8S/޾���uQe���D�y� ��ͧH�����j�wX � �&z� endstream endobj 8 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >> endobj 9 0 obj << /Type /Font /Subtype /Type1 /Name /F2 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >> endobj xref 0 10 0000000000 65535 f 0000000009 00000 n 0000000074 00000 n 0000000120 00000 n 0000000284 00000 n 0000000313 00000 n 0000000514 00000 n 0000000617 00000 n 0000001593 00000 n 0000001700 00000 n trailer << /Size 10 /Root 1 0 R /Info 5 0 R /ID[] >> startxref 1812 %%EOF
Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 128

Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 129

Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 130

Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 131
 ecg@sgdZddlmZddlZddlZddlmZddl m Z ddl m Z ddl m Zdd l mZdd l mZd d l mZd d l mZd dl mZd dl mZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlm Z d dlmZ!d dl"m#Z#d dl$m%Z%d dl$m&Z&d dl$m'Z'd dl$m(Z(d dl$m)Z)d dl$m*Z*d d l$m+Z+d d!l$m,Z,d d"l$m-Z-d d#l$m.Z.d d$l$m/Z/ej0d%ej1Z2ej0d&ej1ej3BZ4e5d'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~ddddddddddddddgfZ6ddfZ7ddddfZ8dddddddfZ9de j:fdYZ;de j<fdYZ=de j>fdYZ?e?Z@de j>fdYZAeAZBde j>fdYZCeCZDde j>fdYZEeEZFde j>fdYZGde j>fdYZHde j>fdYZIde jJfdYZJde jKfdYZKde jLe jMfdYZNeNZOde j>fdYZPePZQde j>fdYZeZRde j>fdYZSde jLe jTfdYZUdejVfdYZWie jXe jX6eNe jY6eUe jT6ejZe j[jZ6ej[e j[6Z\i+e jXd6ej]d6ej[d6ej^d6ej_d6ej`d6ejad6ejbd6ejcd6ejdd6e*d6e%d6e-d6e/d6e'd6e jed6e jed6e.d6e+d6e)d6e,d6e?d6eAd6ed6ePd6ePd6eCd6eEd6eGd6eHd6eId6e=d6eJd6eJd6eJd6eKd6eKd6e(d6eKd6e;d6e&d6eNd6eSd6ZfdejgfdYZhdejifdYZjdejkfdYZldejmfdYZndejofdYZpdejqfdYZrdejqfdYZsdejtfdYZudejvfdYZwdejvfdYZxdejyfdYZzdS(s .. dialect:: postgresql :name: PostgreSQL :full_support: 12, 13, 14, 15 :normal_support: 9.6+ :best_effort: 8+ .. _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:`_sa.create_engine`. PostgreSQL 10 and above IDENTITY columns ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PostgreSQL 10 and above have a new IDENTITY feature that supersedes the use of SERIAL. The :class:`_schema.Identity` construct in a :class:`_schema.Column` can be used to control its behavior:: from sqlalchemy import Table, Column, MetaData, Integer, Computed metadata = MetaData() data = Table( "data", metadata, Column( 'id', Integer, Identity(start=42, cycle=True), primary_key=True ), Column('data', String) ) The CREATE TABLE for the above :class:`_schema.Table` object would be: .. sourcecode:: sql CREATE TABLE data ( id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 42 CYCLE), data VARCHAR, PRIMARY KEY (id) ) .. versionchanged:: 1.4 Added :class:`_schema.Identity` construct in a :class:`_schema.Column` to specify the option of an autoincrementing column. .. note:: Previous versions of SQLAlchemy did not have built-in support for rendering of IDENTITY, and could use the following compilation hook 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, data VARCHAR, PRIMARY KEY (id) ) .. _postgresql_ss_cursors: Server Side Cursors ------------------- Server-side cursor support is available for the psycopg2, asyncpg dialects and may also be available in others. Server side cursors are enabled on a per-statement basis by using the :paramref:`.Connection.execution_options.stream_results` connection execution option:: with engine.connect() as conn: result = conn.execution_options(stream_results=True).execute(text("select * from table")) Note that some kinds of SQL statements may not be supported with server side cursors; generally, only SQL statements that return rows should be used with this option. .. deprecated:: 1.4 The dialect-level server_side_cursors flag is deprecated and will be removed in a future release. Please use the :paramref:`_engine.Connection.stream_results` execution option for unbuffered cursor support. .. seealso:: :ref:`engine_stream_results` .. _postgresql_isolation_level: Transaction Isolation Level --------------------------- Most SQLAlchemy dialects support setting of transaction isolation level using the :paramref:`_sa.create_engine.isolation_level` parameter at the :func:`_sa.create_engine` level, and at the :class:`_engine.Connection` level via the :paramref:`.Connection.execution_options.isolation_level` parameter. For PostgreSQL dialects, this feature works either by making use of the DBAPI-specific features, such as psycopg2's isolation level flags which will embed the isolation level setting inline with the ``"BEGIN"`` statement, or for DBAPIs with no direct support by emitting ``SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL `` ahead of the ``"BEGIN"`` statement emitted by the DBAPI. For the special AUTOCOMMIT isolation level, DBAPI-specific techniques are used which is typically an ``.autocommit`` flag on the DBAPI connection object. To set isolation level using :func:`_sa.create_engine`:: engine = create_engine( "postgresql+pg8000://scott:tiger@localhost/test", isolation_level = "REPEATABLE READ" ) To set using per-connection execution options:: with engine.connect() as conn: conn = conn.execution_options( isolation_level="REPEATABLE READ" ) with conn.begin(): # ... work with transaction There are also more options for isolation level configurations, such as "sub-engine" objects linked to a main :class:`_engine.Engine` which each apply different isolation level settings. See the discussion at :ref:`dbapi_autocommit` for background. Valid values for ``isolation_level`` on most PostgreSQL dialects include: * ``READ COMMITTED`` * ``READ UNCOMMITTED`` * ``REPEATABLE READ`` * ``SERIALIZABLE`` * ``AUTOCOMMIT`` .. seealso:: :ref:`dbapi_autocommit` :ref:`postgresql_readonly_deferrable` :ref:`psycopg2_isolation_level` :ref:`pg8000_isolation_level` .. _postgresql_readonly_deferrable: Setting READ ONLY / DEFERRABLE ------------------------------ Most PostgreSQL dialects support setting the "READ ONLY" and "DEFERRABLE" characteristics of the transaction, which is in addition to the isolation level setting. These two attributes can be established either in conjunction with or independently of the isolation level by passing the ``postgresql_readonly`` and ``postgresql_deferrable`` flags with :meth:`_engine.Connection.execution_options`. The example below illustrates passing the ``"SERIALIZABLE"`` isolation level at the same time as setting "READ ONLY" and "DEFERRABLE":: with engine.connect() as conn: conn = conn.execution_options( isolation_level="SERIALIZABLE", postgresql_readonly=True, postgresql_deferrable=True ) with conn.begin(): # ... work with transaction Note that some DBAPIs such as asyncpg only support "readonly" with SERIALIZABLE isolation. .. versionadded:: 1.4 added support for the ``postgresql_readonly`` and ``postgresql_deferrable`` execution options. .. _postgresql_reset_on_return: Temporary Table / Resource Reset for Connection Pooling ------------------------------------------------------- The :class:`.QueuePool` connection pool implementation used by the SQLAlchemy :class:`_sa.Engine` object includes :ref:`reset on return ` behavior that will invoke the DBAPI ``.rollback()`` method when connections are returned to the pool. While this rollback will clear out the immediate state used by the previous transaction, it does not cover a wider range of session-level state, including temporary tables as well as other server state such as prepared statement handles and statement caches. The PostgreSQL database includes a variety of commands which may be used to reset this state, including ``DISCARD``, ``RESET``, ``DEALLOCATE``, and ``UNLISTEN``. To install one or more of these commands as the means of performing reset-on-return, the :meth:`.PoolEvents.reset` event hook may be used, as demonstrated in the example below (**requires SQLAlchemy 1.4.43 or greater**). The implementation will end transactions in progress as well as discard temporary tables using the ``CLOSE``, ``RESET`` and ``DISCARD`` commands; see the PostgreSQL documentation for background on what each of these statements do. The :paramref:`_sa.create_engine.pool_reset_on_return` parameter is set to ``None`` so that the custom scheme can replace the default behavior completely. The custom hook implementation calls ``.rollback()`` in any case, as it's usually important that the DBAPI's own tracking of commit/rollback will remain consistent with the state of the transaction:: from sqlalchemy import create_engine from sqlalchemy import event postgresql_engine = create_engine( "postgresql+pyscopg2://scott:tiger@hostname/dbname", # disable default reset-on-return scheme pool_reset_on_return=None, ) @event.listens_for(postgresql_engine, "reset") def _reset_postgresql(dbapi_connection, connection_record, reset_state): dbapi_connection.execute("CLOSE ALL") dbapi_connection.execute("RESET ALL") dbapi_connection.execute("DISCARD TEMP") # so that the DBAPI itself knows that the connection has been # reset dbapi_connection.rollback() .. versionchanged:: 1.4.43 Ensured the :meth:`.PoolEvents.reset` event is invoked for all "reset" occurrences, so that it's appropriate as a place for custom "reset" handlers. Previous schemes which use the :meth:`.PoolEvents.checkin` handler remain usable as well. .. seealso:: :ref:`pool_reset_on_return` - in the :ref:`pooling_toplevel` documentation .. _postgresql_alternate_search_path: Setting Alternate Search Paths on Connect ------------------------------------------ The PostgreSQL ``search_path`` variable refers to the list of schema names that will be implicitly referred towards when a particular table or other object is referenced in a SQL statement. As detailed in the next section :ref:`postgresql_schema_reflection`, SQLAlchemy is generally organized around the concept of keeping this variable at its default value of ``public``, however, in order to have it set to any arbitrary name or names when connections are used automatically, the "SET SESSION search_path" command may be invoked for all connections in a pool using the following event handler, as discussed at :ref:`schema_set_default_connections`:: from sqlalchemy import event from sqlalchemy import create_engine engine = create_engine("postgresql+psycopg2://scott:tiger@host/dbname") @event.listens_for(engine, "connect", insert=True) def set_search_path(dbapi_connection, connection_record): existing_autocommit = dbapi_connection.autocommit dbapi_connection.autocommit = True cursor = dbapi_connection.cursor() cursor.execute("SET SESSION search_path='%s'" % schema_name) cursor.close() dbapi_connection.autocommit = existing_autocommit The reason the recipe is complicated by use of the ``.autocommit`` DBAPI attribute is so that when the ``SET SESSION search_path`` directive is invoked, it is invoked outside of the scope of any transaction and therefore will not be reverted when the DBAPI connection has a rollback. .. seealso:: :ref:`schema_set_default_connections` - in the :ref:`metadata_toplevel` documentation .. _postgresql_schema_reflection: Remote-Schema Table Introspection and PostgreSQL search_path ------------------------------------------------------------ .. admonition:: Section Best Practices Summarized keep the ``search_path`` variable set to its default of ``public``, without any other schema names. For other schema names, name these explicitly within :class:`_schema.Table` definitions. Alternatively, the ``postgresql_ignore_search_path`` option will cause all reflected :class:`_schema.Table` objects to have a :attr:`_schema.Table.schema` attribute set up. The PostgreSQL dialect can reflect tables from any schema, as outlined in :ref:`metadata_reflection_schemas`. With regards to tables which these :class:`_schema.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, text >>> engine = create_engine("postgresql://scott:tiger@localhost/test") >>> with engine.connect() as conn: ... conn.execute(text("SET search_path TO test_schema, public")) ... metadata_obj = MetaData() ... referring = Table('referring', metadata_obj, ... autoload_with=conn) ... The above process would deliver to the :attr:`_schema.MetaData.tables` collection ``referred`` table named **without** the schema:: >>> metadata_obj.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:`_schema.Table` as well as :meth:`_schema.MetaData.reflect`:: >>> with engine.connect() as conn: ... conn.execute(text("SET search_path TO test_schema, public")) ... metadata_obj = MetaData() ... referring = Table('referring', metadata_obj, ... autoload_with=conn, ... postgresql_ignore_search_path=True) ... We will now have ``test_schema.referred`` stored as schema-qualified:: >>> metadata_obj.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:`_schema.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``. .. seealso:: :ref:`reflection_schema_qualified_interaction` - discussion of the issue from a backend-agnostic perspective `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.insert()` function, which provides the generative methods :meth:`_postgresql.Insert.on_conflict_do_update` and :meth:`~.postgresql.Insert.on_conflict_do_nothing`: .. sourcecode:: pycon+sql >>> 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'] ... ) >>> print(do_nothing_stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT (id) DO NOTHING {stop} >>> do_update_stmt = insert_stmt.on_conflict_do_update( ... constraint='pk_my_table', ... set_=dict(data='updated value') ... ) >>> print(do_update_stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT ON CONSTRAINT pk_my_table DO UPDATE SET data = %(param_1)s .. versionadded:: 1.1 .. seealso:: `INSERT .. ON CONFLICT `_ - in the PostgreSQL documentation. Specifying the Target ^^^^^^^^^^^^^^^^^^^^^ Both methods supply the "target" of the conflict using either the named constraint or by column inference: * The :paramref:`_postgresql.Insert.on_conflict_do_update.index_elements` argument specifies a sequence containing string column names, :class:`_schema.Column` objects, and/or SQL expression elements, which would identify a unique index: .. sourcecode:: pycon+sql >>> do_update_stmt = insert_stmt.on_conflict_do_update( ... index_elements=['id'], ... set_=dict(data='updated value') ... ) >>> print(do_update_stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT (id) DO UPDATE SET data = %(param_1)s {stop} >>> do_update_stmt = insert_stmt.on_conflict_do_update( ... index_elements=[my_table.c.id], ... set_=dict(data='updated value') ... ) >>> print(do_update_stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT (id) DO UPDATE SET data = %(param_1)s * When using :paramref:`_postgresql.Insert.on_conflict_do_update.index_elements` to infer an index, a partial index can be inferred by also specifying the use the :paramref:`_postgresql.Insert.on_conflict_do_update.index_where` parameter: .. sourcecode:: pycon+sql >>> 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) ... ) >>> print(stmt) {opensql}INSERT INTO my_table (data, user_email) VALUES (%(data)s, %(user_email)s) ON CONFLICT (user_email) WHERE user_email LIKE %(user_email_1)s DO UPDATE SET data = excluded.data * The :paramref:`_postgresql.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: .. sourcecode:: pycon+sql >>> do_update_stmt = insert_stmt.on_conflict_do_update( ... constraint='my_table_idx_1', ... set_=dict(data='updated value') ... ) >>> print(do_update_stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT ON CONSTRAINT my_table_idx_1 DO UPDATE SET data = %(param_1)s {stop} >>> do_update_stmt = insert_stmt.on_conflict_do_update( ... constraint='my_table_pk', ... set_=dict(data='updated value') ... ) >>> print(do_update_stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT ON CONSTRAINT my_table_pk DO UPDATE SET data = %(param_1)s {stop} * The :paramref:`_postgresql.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:`_schema.Table` using the :attr:`_schema.Table.primary_key` attribute: .. sourcecode:: pycon+sql >>> do_update_stmt = insert_stmt.on_conflict_do_update( ... constraint=my_table.primary_key, ... set_=dict(data='updated value') ... ) >>> print(do_update_stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT (id) DO UPDATE SET data = %(param_1)s The SET Clause ^^^^^^^^^^^^^^^ ``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:`_postgresql.Insert.on_conflict_do_update.set_` parameter. This parameter accepts a dictionary which consists of direct values for UPDATE: .. sourcecode:: pycon+sql >>> 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') ... ) >>> print(do_update_stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT (id) DO UPDATE SET data = %(param_1)s .. warning:: The :meth:`_expression.Insert.on_conflict_do_update` method does **not** take into account Python-side default UPDATE values or generation functions, e.g. those specified using :paramref:`_schema.Column.onupdate`. These values will not be exercised for an ON CONFLICT style of UPDATE, unless they are manually specified in the :paramref:`_postgresql.Insert.on_conflict_do_update.set_` dictionary. Updating using the Excluded INSERT Values ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ In order to refer to the proposed insertion row, the special alias :attr:`~.postgresql.Insert.excluded` is available as an attribute on the :class:`_postgresql.Insert` object; this object is a :class:`_expression.ColumnCollection` which alias contains all columns of the target table: .. sourcecode:: pycon+sql >>> 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) ... ) >>> print(do_update_stmt) {opensql}INSERT INTO my_table (id, data, author) VALUES (%(id)s, %(data)s, %(author)s) ON CONFLICT (id) DO UPDATE SET data = %(param_1)s, author = excluded.author Additional WHERE Criteria ^^^^^^^^^^^^^^^^^^^^^^^^^ The :meth:`_expression.Insert.on_conflict_do_update` method also accepts a WHERE clause using the :paramref:`_postgresql.Insert.on_conflict_do_update.where` parameter, which will limit those rows which receive an UPDATE: .. sourcecode:: pycon+sql >>> 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) ... ) >>> print(on_update_stmt) {opensql}INSERT INTO my_table (id, data, author) VALUES (%(id)s, %(data)s, %(author)s) ON CONFLICT (id) DO UPDATE SET data = %(param_1)s, author = excluded.author WHERE my_table.status = %(status_1)s Skipping Rows with DO NOTHING ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``ON CONFLICT`` may 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.Insert.on_conflict_do_nothing` method: .. sourcecode:: pycon+sql >>> stmt = insert(my_table).values(id='some_id', data='inserted value') >>> stmt = stmt.on_conflict_do_nothing(index_elements=['id']) >>> print(stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT (id) DO NOTHING 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: .. sourcecode:: pycon+sql >>> stmt = insert(my_table).values(id='some_id', data='inserted value') >>> stmt = stmt.on_conflict_do_nothing() >>> print(stmt) {opensql}INSERT INTO my_table (id, data) VALUES (%(id)s, %(data)s) ON CONFLICT DO NOTHING .. _postgresql_match: Full Text Search ---------------- SQLAlchemy makes available the PostgreSQL ``@@`` operator via the :meth:`_expression.ColumnElement.match` method on any textual column expression. On the 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 Various other PostgreSQL text search functions such as ``to_tsquery()``, ``to_tsvector()``, and ``plainto_tsquery()`` are available by explicitly using the standard SQLAlchemy :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 .. tip:: It's important to remember that text searching in PostgreSQL is powerful but complicated, and SQLAlchemy users are advised to reference the PostgreSQL documentation regarding `Full Text Search `_. There are important differences between ``to_tsquery`` and ``plainto_tsquery``, the most significant of which is that ``to_tsquery`` expects specially formatted "querytext" that is written to PostgreSQL's own specification, while ``plainto_tsquery`` expects unformatted text that is transformed into ``to_tsquery`` compatible querytext. This means the input to ``.match()`` under PostgreSQL may be incompatible with the input to ``.match()`` under another database backend. SQLAlchemy users who support multiple backends are advised to carefully implement their usage of ``.match()`` to work around these constraints. 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. .. seealso:: `Full Text Search `_ - in the PostgreSQL documentation 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. Covering Indexes ^^^^^^^^^^^^^^^^ The ``postgresql_include`` option renders INCLUDE(colname) for the given string names:: Index("my_index", table.c.x, postgresql_include=['y']) would render the index as ``CREATE INDEX my_index ON table (x) INCLUDE (y)`` Note that this feature requires PostgreSQL 11 or later. .. versionadded:: 1.4 .. _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) .. _postgresql_operator_classes: Operator Classes ^^^^^^^^^^^^^^^^ PostgreSQL allows the specification of an *operator class* for each column of an index (see https://www.postgresql.org/docs/current/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`` dictionaries are the "key" name of the :class:`_schema.Column`, i.e. the name used to access it from the ``.c`` collection of :class:`_schema.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' }) Operator classes are also supported by the :class:`_postgresql.ExcludeConstraint` construct using the :paramref:`_postgresql.ExcludeConstraint.ops` parameter. See that parameter for details. .. versionadded:: 1.3.21 added support for operator classes with :class:`_postgresql.ExcludeConstraint`. 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 https://www.postgresql.org/docs/current/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:`_schema.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:`_reflection.Inspector`, the :meth:`_reflection.Inspector.get_indexes` and the :meth:`_reflection.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_with=engine)``, the UNIQUE INDEX is **not** returned in :attr:`_schema.Table.indexes` when it is detected as mirroring a :class:`.UniqueConstraint` in the :attr:`_schema.Table.constraints` collection . .. versionchanged:: 1.0.0 - :class:`_schema.Table` reflection now includes :class:`.UniqueConstraint` objects present in the :attr:`_schema.Table.constraints` collection; the PostgreSQL backend will no longer include a "mirrored" :class:`.Index` construct in :attr:`_schema.Table.indexes` if it is detected as corresponding to a unique constraint. Special Reflection Options -------------------------- The :class:`_reflection.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:`_schema.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 `_ - in the PostgreSQL documentation. .. _postgresql_constraint_options: PostgreSQL Constraint Options ----------------------------- The following option(s) are supported by the PostgreSQL dialect in conjunction with selected constraint constructs: * ``NOT VALID``: This option applies towards CHECK and FOREIGN KEY constraints when the constraint is being added to an existing table via ALTER TABLE, and has the effect that existing rows are not scanned during the ALTER operation against the constraint being added. When using a SQL migration tool such as `Alembic `_ that renders ALTER TABLE constructs, the ``postgresql_not_valid`` argument may be specified as an additional keyword argument within the operation that creates the constraint, as in the following Alembic example:: def update(): op.create_foreign_key( "fk_user_address", "address", "user", ["user_id"], ["id"], postgresql_not_valid=True ) The keyword is ultimately accepted directly by the :class:`_schema.CheckConstraint`, :class:`_schema.ForeignKeyConstraint` and :class:`_schema.ForeignKey` constructs; when using a tool like Alembic, dialect-specific keyword arguments are passed through to these constructs from the migration operation directives:: CheckConstraint("some_field IS NOT NULL", postgresql_not_valid=True) ForeignKeyConstraint(["some_id"], ["some_table.some_id"], postgresql_not_valid=True) .. versionadded:: 1.4.32 .. seealso:: `PostgreSQL ALTER TABLE options `_ - in the PostgreSQL documentation. .. _postgresql_table_valued_overview: Table values, Table and Column valued functions, Row and Tuple objects ----------------------------------------------------------------------- PostgreSQL makes great use of modern SQL forms such as table-valued functions, tables and rows as values. These constructs are commonly used as part of PostgreSQL's support for complex datatypes such as JSON, ARRAY, and other datatypes. SQLAlchemy's SQL expression language has native support for most table-valued and row-valued forms. .. _postgresql_table_valued: Table-Valued Functions ^^^^^^^^^^^^^^^^^^^^^^^ Many PostgreSQL built-in functions are intended to be used in the FROM clause of a SELECT statement, and are capable of returning table rows or sets of table rows. A large portion of PostgreSQL's JSON functions for example such as ``json_array_elements()``, ``json_object_keys()``, ``json_each_text()``, ``json_each()``, ``json_to_record()``, ``json_populate_recordset()`` use such forms. These classes of SQL function calling forms in SQLAlchemy are available using the :meth:`_functions.FunctionElement.table_valued` method in conjunction with :class:`_functions.Function` objects generated from the :data:`_sql.func` namespace. Examples from PostgreSQL's reference documentation follow below: * ``json_each()``:: >>> from sqlalchemy import select, func >>> stmt = select(func.json_each('{"a":"foo", "b":"bar"}').table_valued("key", "value")) >>> print(stmt) SELECT anon_1.key, anon_1.value FROM json_each(:json_each_1) AS anon_1 * ``json_populate_record()``:: >>> from sqlalchemy import select, func, literal_column >>> stmt = select( ... func.json_populate_record( ... literal_column("null::myrowtype"), ... '{"a":1,"b":2}' ... ).table_valued("a", "b", name="x") ... ) >>> print(stmt) SELECT x.a, x.b FROM json_populate_record(null::myrowtype, :json_populate_record_1) AS x * ``json_to_record()`` - this form uses a PostgreSQL specific form of derived columns in the alias, where we may make use of :func:`_sql.column` elements with types to produce them. The :meth:`_functions.FunctionElement.table_valued` method produces a :class:`_sql.TableValuedAlias` construct, and the method :meth:`_sql.TableValuedAlias.render_derived` method sets up the derived columns specification:: >>> from sqlalchemy import select, func, column, Integer, Text >>> stmt = select( ... func.json_to_record('{"a":1,"b":[1,2,3],"c":"bar"}').table_valued( ... column("a", Integer), column("b", Text), column("d", Text), ... ).render_derived(name="x", with_types=True) ... ) >>> print(stmt) SELECT x.a, x.b, x.d FROM json_to_record(:json_to_record_1) AS x(a INTEGER, b TEXT, d TEXT) * ``WITH ORDINALITY`` - part of the SQL standard, ``WITH ORDINALITY`` adds an ordinal counter to the output of a function and is accepted by a limited set of PostgreSQL functions including ``unnest()`` and ``generate_series()``. The :meth:`_functions.FunctionElement.table_valued` method accepts a keyword parameter ``with_ordinality`` for this purpose, which accepts the string name that will be applied to the "ordinality" column:: >>> from sqlalchemy import select, func >>> stmt = select( ... func.generate_series(4, 1, -1). ... table_valued("value", with_ordinality="ordinality"). ... render_derived() ... ) >>> print(stmt) SELECT anon_1.value, anon_1.ordinality FROM generate_series(:generate_series_1, :generate_series_2, :generate_series_3) WITH ORDINALITY AS anon_1(value, ordinality) .. versionadded:: 1.4.0b2 .. seealso:: :ref:`tutorial_functions_table_valued` - in the :ref:`unified_tutorial` .. _postgresql_column_valued: Column Valued Functions ^^^^^^^^^^^^^^^^^^^^^^^ Similar to the table valued function, a column valued function is present in the FROM clause, but delivers itself to the columns clause as a single scalar value. PostgreSQL functions such as ``json_array_elements()``, ``unnest()`` and ``generate_series()`` may use this form. Column valued functions are available using the :meth:`_functions.FunctionElement.column_valued` method of :class:`_functions.FunctionElement`: * ``json_array_elements()``:: >>> from sqlalchemy import select, func >>> stmt = select(func.json_array_elements('["one", "two"]').column_valued("x")) >>> print(stmt) SELECT x FROM json_array_elements(:json_array_elements_1) AS x * ``unnest()`` - in order to generate a PostgreSQL ARRAY literal, the :func:`_postgresql.array` construct may be used:: >>> from sqlalchemy.dialects.postgresql import array >>> from sqlalchemy import select, func >>> stmt = select(func.unnest(array([1, 2])).column_valued()) >>> print(stmt) SELECT anon_1 FROM unnest(ARRAY[%(param_1)s, %(param_2)s]) AS anon_1 The function can of course be used against an existing table-bound column that's of type :class:`_types.ARRAY`:: >>> from sqlalchemy import table, column, ARRAY, Integer >>> from sqlalchemy import select, func >>> t = table("t", column('value', ARRAY(Integer))) >>> stmt = select(func.unnest(t.c.value).column_valued("unnested_value")) >>> print(stmt) SELECT unnested_value FROM unnest(t.value) AS unnested_value .. seealso:: :ref:`tutorial_functions_column_valued` - in the :ref:`unified_tutorial` Row Types ^^^^^^^^^ Built-in support for rendering a ``ROW`` may be approximated using ``func.ROW`` with the :attr:`_sa.func` namespace, or by using the :func:`_sql.tuple_` construct:: >>> from sqlalchemy import table, column, func, tuple_ >>> t = table("t", column("id"), column("fk")) >>> stmt = t.select().where( ... tuple_(t.c.id, t.c.fk) > (1,2) ... ).where( ... func.ROW(t.c.id, t.c.fk) < func.ROW(3, 7) ... ) >>> print(stmt) SELECT t.id, t.fk FROM t WHERE (t.id, t.fk) > (:param_1, :param_2) AND ROW(t.id, t.fk) < ROW(:ROW_1, :ROW_2) .. seealso:: `PostgreSQL Row Constructors `_ `PostgreSQL Row Constructor Comparison `_ Table Types passed to Functions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PostgreSQL supports passing a table as an argument to a function, which it refers towards as a "record" type. SQLAlchemy :class:`_sql.FromClause` objects such as :class:`_schema.Table` support this special form using the :meth:`_sql.FromClause.table_valued` method, which is comparable to the :meth:`_functions.FunctionElement.table_valued` method except that the collection of columns is already established by that of the :class:`_sql.FromClause` itself:: >>> from sqlalchemy import table, column, func, select >>> a = table( "a", column("id"), column("x"), column("y")) >>> stmt = select(func.row_to_json(a.table_valued())) >>> print(stmt) SELECT row_to_json(a) AS row_to_json_1 FROM a .. versionadded:: 1.4.0b2 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. Prior to SQLAlchemy 1.3.17, a special workaround was needed in order to allow this combination to work, described below. .. versionchanged:: 1.3.17 The combination of ENUM and ARRAY is now directly handled by SQLAlchemy's implementation without any workarounds needed. .. 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, prior to SQLAlchemy 1.3.17, for an ARRAY of JSON/JSONB we need to render the appropriate CAST. Current psycopg2 drivers accommodate the result set correctly without any special steps. .. versionchanged:: 1.3.17 The combination of JSON/JSONB and ARRAY is now directly handled by SQLAlchemy's implementation without any workarounds needed. .. sourcecode:: python 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 defaultdictN(tUUIDi(tarray(tdml(thstore(tjson(trangesi(texc(tschema(tsql(tutil(tcharacteristics(tdefault(t reflection(t coercions(tcompiler(telements(t expression(troles(tsqltypes(tDDLBase(tBIGINT(tBOOLEAN(tCHAR(tDATE(tFLOAT(tINTEGER(tNUMERIC(tREAL(tSMALLINT(tTEXT(tVARCHARs ^(?:btree|hash|gist|gin|[\w_]+)$ss\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER|GRANT|REVOKE|IMPORT FOREIGN SCHEMA|REFRESH MATERIALIZED VIEW|TRUNCATE)talltanalysetanalyzetandtanyRtastasct asymmetrictbothtcasetcasttchecktcollatetcolumnt constrainttcreatetcurrent_catalogt current_datet current_rolet current_timetcurrent_timestampt current_userR t 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.pyRustDOUBLE_PRECISIONcBseZdZRS(R(RRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRystINETcBseZdZRS(R(RRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR}stCIDRcBseZdZRS(R(RRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstMACADDRcBseZdZRS(R(RRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstMACADDR8cBseZdZRS(R(RRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstMONEYcBseZdZdZRS(sProvide the PostgreSQL MONEY type. Depending on driver, result rows using this type may return a string value which includes currency symbols. For this reason, it may be preferable to provide conversion to a numerically-based currency datatype using :class:`_types.TypeDecorator`:: import re import decimal from sqlalchemy import TypeDecorator class NumericMoney(TypeDecorator): impl = MONEY def process_result_value(self, value: Any, dialect: Any) -> None: if value is not None: # adjust this for the currency and numeric m = re.match(r"\$([\d.]+)", value) if m: value = decimal.Decimal(m.group(1)) return value Alternatively, the conversion may be applied as a CAST using the :meth:`_types.TypeDecorator.column_expression` method as follows:: import decimal from sqlalchemy import cast from sqlalchemy import TypeDecorator class NumericMoney(TypeDecorator): impl = MONEY def column_expression(self, column: Any): return cast(column, Numeric()) .. versionadded:: 1.2 R(RRt__doc__R(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs(tOIDcBseZdZdZRS(sCProvide the PostgreSQL OID type. .. versionadded:: 0.9.5 R(RRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstREGCLASScBseZdZdZRS(sHProvide the PostgreSQL REGCLASS type. .. versionadded:: 1.2.7 R(RRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRst TIMESTAMPcBs#eZdZdZeddZRS(s&Provide the PostgreSQL TIMESTAMP type.RcCs&tt|jd|||_dS(sConstruct a TIMESTAMP. :param timezone: boolean value if timezone present, default False :param precision: optional integer precision value .. versionadded:: 1.4 ttimezoneN(tsuperRt__init__t precision(tselfRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs N(RRRRtFalsetNoneR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstTIMEcBs#eZdZdZeddZRS(sPostgreSQL TIME type.RcCs&tt|jd|||_dS(sConstruct a TIME. :param timezone: boolean value if timezone present, default False :param precision: optional integer precision value .. versionadded:: 1.4 RN(RRRR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs N(RRRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstINTERVALcBskeZdZdZeZdddZedZ e dZ e dZ e dZdZRS( sPostgreSQL INTERVAL type.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.pyR s cKstd|jS(NR(Rtsecond_precision(tclstintervaltkw((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytadapt_emulated_to_nativescCstjS(N(RtInterval(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_type_affinityscCstjdtd|jS(NtnativeR(RRtTrueR(Rtallow_nulltype((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt as_genericscCstjS(N(tdtt timedelta(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt python_type"scCs|S(N((Rtoptvalue((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytcoerce_compared_value&sN(RRRRRRRRt classmethodRtpropertyRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs tBITcBseZdZdedZRS(RcCs.|s|pd|_n ||_||_dS(Ni(tlengthtvarying(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR0s N(RRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR-sRcBsSeZdZdZedZdZdZdZdZ e dZ RS(szPostgreSQL UUID type. Represents the UUID column type, interpreting data either as natively returned by the DBAPI or as Python uuid objects. The UUID type is currently known to work within the prominent DBAPI drivers supported by SQLAlchemy including psycopg2, pg8000 and asyncpg. Support for other DBAPI drivers may be incomplete or non-present. RcCs ||_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. N(tas_uuid(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRMs cCs3t|tjr|Stt|j||SdS(s@See :meth:`.TypeEngine.coerce_compared_value` for a description.N(t isinstanceR t string_typesRRR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRXscCs|jrd}|SdSdS(NcSs"|dk rtj|}n|S(N(RR t text_type(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytprocesscs (RR(RtdialectR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytbind_processor`s  cCs|jrd}|SdSdS(NcSs|dk rt|}n|S(N(Rt _python_UUID(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRos (RR(RRtcoltypeR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytresult_processorls  cCs'|jrd}|Sd}|SdS(NcSs|dk rd|}n|S(Ns '%s'::UUID(R(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR{s  cSs|dk rd|}n|S(Ns'%s'(R(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs  (R(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytliteral_processorxs    cCs|jr tStS(N(RRtstr(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs( RRRRRRRRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR=s   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(RRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRstENUMcBseZdZeZdZedZdedZ dedZ de fdYZ de fdYZ d Zed Zed Zed Zed 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:`_schema.Table.create` and :meth:`_schema.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:`_schema.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. cOs`|jdd}|tkr.tjdn|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 native_enumsthe native_enum flag does not apply to the sqlalchemy.dialects.postgresql.ENUM datatype; this type always refers to ENUM. Use sqlalchemy.types.Enum for non-native enum.t create_typeN( tpopRRR twarnRRRRR(RtenumsRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs   cKs|jd|j|jd|j|jd|j|jd|j|jd|j|jdt|jd|j|jd|j||S( sbProduce a PostgreSQL native :class:`_postgresql.ENUM` from plain :class:`.Enum`. tvalidate_stringstnameRtinherit_schematmetadatat_create_eventstvalues_callablet omit_aliases( t setdefaultRRRRRRRt _omit_aliases(RtimplR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRscCs-|jjsdS|j|j|d|dS(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.Engine`, :class:`_engine.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. Nt checkfirst(Rtsupports_native_enumt_run_ddl_visitort EnumGenerator(RtbindR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR/,s cCs-|jjsdS|j|j|d|dS(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.Engine`, :class:`_engine.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(RRRt EnumDropper(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdropAs RcBs&eZedZdZdZRS(cKs)ttj|j||||_dS(N(RRRRR(RRt connectionRtkwargs((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRVscCsB|js tS|jj|}|jjj|j|jd| S(NR(RRRtschema_for_objectRthas_typeR(Rtenumteffective_schema((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_can_create_enumZs   cCs-|j|sdS|jjt|dS(N(RRtexecutetCreateEnumType(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_enumds(RRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRUs  RcBs&eZedZdZdZRS(cKs)ttj|j||||_dS(N(RRRRR(RRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRkscCsA|js tS|jj|}|jjj|j|jd|S(NR(RRRRRRR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_can_drop_enumos   cCs-|j|sdS|jjt|dS(N(RRRt DropEnumType(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRys(RRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRjs  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|s#|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(RRRRRRRRRR/RRRRRRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRsM &   t _ColonCastcBseZdZdZRS(t colon_castcCs(||_||_tj||_dS(N(ttypetclauseRt TypeClauset typeclause(RRttype_((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs  (RRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRst_arrayRRtjsonbt int4ranget int8rangetnumranget daterangettsranget tstzrangetintegertbiginttsmallintscharacter varyingt characters"char"Rttexttnumerictfloattrealtinettcidrtuuidtbits bit varyingtmacaddrtmacaddr8tmoneytoidtregclasssdouble precisiont timestampstimestamp with time zonestimestamp without time zonestime with time zonestime without time zonetdatettimetbyteatbooleanRttsvectort PGCompilercBs%eZdZdZdZedZedZdZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZdZejdZdZdZdZ dZ!dZ"RS(cKs,d|jj|||jj||fS(Ns%s::%s(Rt_compiler_dispatchR(RtelementR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_colon_castscKsd|j||S(Ns ARRAY[%s](tvisit_clauselist(RRR((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_slicescKsn| rE|jjtjk rEt|d<|jtj||j|St|d<|j||sddnd|S(Nt _cast_appliedteager_groupings -> s ->> ( RRRtJSONRRR R*t_generate_generic_binary(RRptoperatorR!R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_json_getitem_op_binary s  cKsn| rE|jjtjk rEt|d<|jtj||j|St|d<|j||sddnd|S(NR!R"s #> s #>> ( RRRR#RRR R*R$(RRpR%R!R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt!visit_json_path_getitem_op_binary s  cKs,d|j|j||j|j|fS(Ns%s[%s](RRzR(RRpR%R((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_valueRt STRINGTYPERRzR(RRpR%Rt 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( R,RRRRzRR-RR.(RRpR%RR1((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(NR1s%s NOT ILIKE %ss ESCAPE R2( R,RRRRzRR-RR.(RRpR%RR1((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_not_ilike_op_binaryI s cCs|jd}|dkr0|j|d||S|dkrS|j|d||Sd|j|j|||j|tj|j|j|fS(Ntflagss %s tis %s* s%s %s CONCAT('(?', %s, ')', %s)( R,RR$RRzR-RR.R(Rtbase_opRpR%RR5((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt _regexp_matchT s   cKs|jd|||S(Nt~(R8(RRpR%R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_regexp_match_op_binarye scKs|jd|||S(Ns!~(R8(RRpR%R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_not_regexp_match_op_binaryh scKsu|j|j|}|j|j|}|jd}|dkrQd||fSd|||j|tjfSdS(NR5sREGEXP_REPLACE(%s, %s)sREGEXP_REPLACE(%s, %s, %s)(RRzRR,RR-RR.(RRpR%Rtstringtpattern_replaceR5((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_regexp_replace_op_binaryk s  cs0ddjfd|p$tgDfS(NsSELECT %s WHERE 1!=1s, c3s:|]0}djjj|jr*tn|VqdS(sCAST(NULL AS %s)N(Rt type_compilerRt_isnullR(t.0R(R(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys s(RyR(Rt element_types((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_empty_set_expr{ s cCs@tt|j||}|jjr<|jdd}n|S(Ns\s\\(RRR-Rt_backslash_escapestreplace(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR- s cKsd|jj|S(Ns nextval('%s')(tpreparertformat_sequence(RtseqR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_sequence scKsd}|jdk r5|d|j|j|7}n|jdk r|jdkr`|d7}n|d|j|j|7}n|S(NR2s LIMIT s LIMIT ALLs OFFSET (t _limit_clauseRRt_offset_clause(RR\RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt limit_clause s   cCs0|jdkr(tjd|nd|S(NtONLYsUnrecognized hint: %rsONLY (tupperRt CompileError(RtsqltextR`thinttiscrud((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytformat_from_hint_text scKsa|js|jrY|jrRddjg|jD]}|j||^q.dSdSndSdS(Ns DISTINCT ON (s, s) s DISTINCT R2(t _distinctt _distinct_onRyR(RR\Rtcol((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_select_precolumns s  7c 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(RAR`(RR(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys ss NOWAITs SKIP LOCKED( t_for_update_argtreadt key_shareRPR t OrderedSettupdatetsql_utiltsurface_selectables_onlyRytnowaitt skip_locked(RR\Rttmpttablestc((RRsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytfor_update_clause s&             cCsHgtj|D]!}|j||d|j^q}ddj|S(Ntfallback_label_names RETURNING s, (Rt_select_iterablest_label_returning_columnt_non_anon_labelRy(Rtstmttreturning_colsRetcolumns((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytreturning_clause s4cKs|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_func s c s|jdk r+djj|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_tableRYN(RR RRFtquoteRR(RARe(R(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys ss WHERE %sRtRYR2( tconstraint_targetRRFt#truncate_and_render_constraint_nametinferred_target_elementsRytinferred_target_whereclauseRR(RRRt target_text((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_on_conflict_target s     cCs7|jdk o6|jjdkp6t|jjtjS(N(tinsert_single_values_exprRt statementt_post_values_clauseRRtOnConflictDoNothing(R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt&_is_safe_for_fast_insert_values_helper s cKs(|j||}|r d|SdSdS(NsON CONFLICT %s DO NOTHINGsON CONFLICT DO NOTHING(R{(Rt on_conflictRRz((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_on_conflict_do_nothing scKsr|}|j||}g}t|j}|jdd}|jj}x|D]} | j} | |kr~|j| } n!| |krQ|j| } nqQtj | rt j d| d| j } n9t| t j r| j jr| j} | j | _ n|j| jdt} |jj| j} |jd| | fqQW|rtjd|jjjdjd|Dfx|jD]\}}t|tjr|jj|n|j|dt} |jtjtj |dt} |jd| | fqWndj|}|j!dk rd|d |j|j!d t"dt7}nd ||fS( Nit selectableRRYs%s = %ssFAdditional column names not matching any column keys in table '%s': %ss, css|]}d|VqdS(s'%s'N((RARe((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys R ss WHERE %sRtsON CONFLICT %s DO UPDATE SET %s(#R{tdicttupdate_values_to_settstackR`RetkeyRRt _is_literalRt BindParameterRRRR@t_cloneRt self_groupRRFRuRtappendR Rtcurrent_executableRytitemsRtexpectRtExpressionElementRoletupdate_whereclauseR(RRRRRztaction_set_opstset_parameterstinsert_statementtcolsRetcol_keyRt value_texttkey_texttktvt action_text((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_on_conflict_do_update% sN        $  c s1tdn s(RRy(Rt update_stmtt from_tablet extra_fromsRR((RRRsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytupdate_from_clausei s  c s1tdx s(RRy(Rt delete_stmtRRRR((RRRsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdelete_extra_from_clauser s  cKsd}|jdk r5|d|j|j|7}n|jdk r|d|j|j||jdrodnd|jdrdndf7}n|S( NR2s OFFSET (%s) ROWSs FETCH FIRST (%s)%s ROWS %stpercents PERCENTt with_tiess WITH TIESRM(RKRRt _fetch_clauset_fetch_clause_options(RR\RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt fetch_clause| s (#RRRRR RR&R'R(R*R0R3R4R8R:R;R>RCR-RIRLRSRWRfRnRsR{R tmemoized_propertyRRRRRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs<                   " D t PGDDLCompilercBs}eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d ZRS( cKs|jj|}|jj|j}t|tjrE|j}n|j dk o]|jj }|j r||j jkr|jjst|tj r| r|jdkst|jtjr|jjrt|tjr|d7}qwt|tjr|d7}qw|d7}n[|d|jjj|jd|d|j7}|j|}|dk rw|d|7}n|jdk r|d|j|j7}n|r|d|j|j 7}n|j r| r|d7}n|jr|r|d 7}n|S( Ns BIGSERIALs SMALLSERIALs SERIALt ttype_expressiontidentifier_preparers DEFAULT s NOT NULLs NULL(RFt format_columnRt dialect_implRRRt TypeDecoratorRtidentityRtsupports_identity_columnst primary_keyR`t_autoincrement_columntsupports_smallserialt SmallIntegerR RtSequencetoptionalt BigIntegerR?Rtget_column_default_stringtcomputedtnullable(RR-Rtcolspect impl_typet has_identityR ((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_column_specification sF            cCs|jdd}|rdSdS(Nt postgresqlt not_valids NOT VALIDR2(tdialect_options(RR.R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_define_constraint_validity scCs|jrht|jdj}t|tjrht|jtjrh|jj rht j dqhnt t |j|}||j|7}|S(NisPostgreSQL dialect cannot produce the CHECK constraint for ARRAY of non-native ENUM; please specify create_constraint=False on this Enum datatype.(t _type_boundtlistRmRRRtARRAYt item_typetEnumRRRORRtvisit_check_constraintR(RR.ttypR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR s  cCs/tt|j|}||j|7}|S(N(RRtvisit_foreign_key_constraintR(RR.R((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR s cCsd|jj|jS(NsCOMMENT ON TABLE %s IS NULL(RFt format_tableR(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_drop_table_comment s cs?|j}djj|djfd|jDfS(NsCREATE TYPE %s AS ENUM (%s)s, c3s0|]&}jjtj|dtVqdS(t literal_bindsN(t sql_compilerRR tliteralR(RAte(R(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys s(RRFt format_typeRyR(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(RRFR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_drop_enum_type s c Cs|j}|j}|j|d}|jr;|d7}n|d7}|jjrx|jdd}|rx|d7}qxn|jr|d7}n|d|j|d t |j |j f7}|jdd }|r|d |jj |t j7}n|jdd }|d djg|jD]u}|jjt|tjsN|jn|dt dtt|dr|j|krd||jnd^q!7}|jdd} | r,g| D].} t| tjr|j j| n| ^q} |ddjg| D]} |j| j^q7}n|jdd} | rz|ddjg| jD]}d|^q\7}n|jdd}|r|d|j|7}n|jdd}|dk r t!j"t#j$|}|jj|dt dt}|d|7}n|S(NsCREATE sUNIQUE sINDEX Rt concurrentlys CONCURRENTLY sIF NOT EXISTS s %s ON %s tinclude_schemaRhs USING %s topss(%s)s, RtRRRR2tincludes INCLUDE (%s)Rms WITH (%s)s%s = %st tablespaces TABLESPACE %sRks WHERE (%RFRt_verify_index_tableRfRt#_supports_create_index_concurrentlyRt if_not_existst_prepared_index_nameRRR`tvalidate_sql_phraset IDX_USINGtlowerRyt expressionsRRRRt ColumnClauseRRthasattrRR RReRuRRRRRRtDDLExpressionRole(RR/RFtindexRRRhRtexprt includeclauseRVt inclusionsRet withclausetstorage_parameterttablespace_namet whereclausetwhere_compiled((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_create_index sb           8 -(  cCsu|j}d}|jjrB|jdd}|rB|d7}qBn|jrX|d7}n||j|dt7}|S(Ns DROP INDEX RRs CONCURRENTLY s IF EXISTS R(RRt!_supports_drop_index_concurrentlyRt if_existsRR(RRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_drop_indexT s    c KsEd}|jdk r2|d|jj|7}ng}x|jD]~\}}}t|d<|jj||t|dr|j |j krd|j |j nd}|j d||fqBW|d|jj |j tjdj|f7}|jdk r.|d |jj|jd t7}n||j|7}|S( NR2sCONSTRAINT %s RtRRs %s WITH %ssEXCLUDE USING %s (%s)s, s WHERE (%s)R(RRRFtformat_constraintt _render_exprsRRRRRRRRRhRRRyRkRtdefine_constraint_deferrability( RR.RRRRRRtexclude_element((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_exclude_constraintd s( 5 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(RFRu(RAR(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_Rs ON COMMIT %sRs TABLESPACE %sR2(RRRRRttupleRRyRRRERNRFRu(RR`t table_optstpg_optsRton_commit_optionsR((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytpost_create_table s,   +    cCsD|jtkr!tjdnd|jj|jdtdtS(NsPostrgreSQL computed columns do not support 'virtual' persistence; set the 'persisted' flag to None or True for PostgreSQL support.sGENERATED ALWAYS AS (%s) STOREDRtR(t persistedRRRORRRPR(Rt generated((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_computed_column s   cKsVd}|jjdk r7d|jj|jj}ntt|j|d||S(Ns AS %stprefix(RRt data_typeR?RRRtvisit_create_sequence(RR/RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR  s  (RRRRRRRRRRRRRRR (((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR s 7      Z   " tPGTypeCompilercBs"eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZddZdZdZdZdZdZdZdZ dZ!RS( cKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_TSVECTOR scKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_INET scKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_CIDR scKsdS(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.pytvisit_MACADDR8 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_OID scKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_REGCLASS scKs#|js dSdi|jd6SdS(NRsFLOAT(%(precision)s)R(R(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_FLOAT s cKsdS(NsDOUBLE PRECISION((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_DOUBLE_PRECISION scKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_BIGINT scKsdS(NtHSTORE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_HSTORE scKsdS(NR#((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_NUMRANGE scKsdS(Nt DATERANGE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_DATERANGE scKsdS(NtTSRANGE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_TSRANGE scKsdS(Nt TSTZRANGE((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_TSTZRANGE scKs|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(RRRRR Rt visit_ENUM(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR scKs(|dkr|jj}n|j|S(N(RRRR(RRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR* s cKsFdt|dddk r(d|jnd|jr:dp=ddfS(NsTIMESTAMP%s %sRs(%d)R2tWITHtWITHOUTs TIME ZONE(tgetattrRRR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR( s%cKsFdt|dddk r(d|jnd|jr:dp=ddfS(Ns TIME%s %sRs(%d)R2R+R,s TIME ZONE(R-RRR(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_TIME s%cKsPd}|jdk r)|d|j7}n|jdk rL|d|j7}n|S(NRRs (%d)(RRR(RRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_INTERVAL s 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_UUID* scKs|j||S(N(t visit_BYTEA(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytvisit_large_binary- scKsdS(NR((RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR30 scKsN|j|j|}tjddd|jdk r<|jnd|ddS(Ns((?: COLLATE.*)?)$s%s\1s[]itcount(RRtretsubt dimensionsR(RRRRv((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt visit_ARRAY3 sN("RRR R RRRRRRRRRRRRRRR!R#R%R'R)RRR*R(R.R/R1R2R4R3R9(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR  s>                             tPGIdentifierPreparercBs#eZeZdZedZRS(cCs9|d|jkr5|dd!j|j|j}n|S(Niii(t initial_quoteREtescape_to_quotet escape_quote(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_unquote_identifierH s cCsv|jstjdn|j|j}|j|}|j rr|rr|dk rr|j|d|}n|S(Ns%PostgreSQL ENUM type requires a name.t.(RRRORuRt omit_schemaRt quote_schema(RRRYRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRO s   (RRtRESERVED_WORDStreserved_wordsR>RR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR:D s t PGInspectorcBs;eZddZddZddZdddZRS(c Cs8|j&}|jj|||d|jSWdQXdS(s(Return the OID for the given table name.t info_cacheN(t_operation_contextRt get_table_oidRE(Rt table_nameRtconn((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRG` s cCs;|p |j}|j}|jj||SWdQXdS(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 N(tdefault_schema_nameRFRt _load_enums(RRRI((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt get_enumsh scCs;|p |j}|j}|jj||SWdQXdS(sReturn a list of FOREIGN TABLE names. Behavior is similar to that of :meth:`_reflection.Inspector.get_table_names`, except that the list is limited to those tables that report a ``relkind`` value of ``f``. .. versionadded:: 1.0.0 N(RJRFRt_get_foreign_table_names(RRRI((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_foreign_table_names~ s tplaint materializedc Cs;|j)}|jj||d|jd|SWdQXdS(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 RERN(RFRtget_view_namesRE(RRRRI((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRQ s N(RORP(RRRRGRLRNRQ(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRD_ s   RcBseZdZRS(tcreate_enum_type(RRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR sRcBseZdZRS(tdrop_enum_type(RRR(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR stPGExecutionContextcBs#eZdZdZdZRS(cCs |jd|jj||S(Nsselect nextval('%s')(t_execute_scalarRRG(RRHR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt fire_sequence scCs|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"')(RR`Rtserver_defaultt has_argumentRUtargRR Rt is_sequenceRt_postgresql_seq_nametAttributeErrorRtmaxRpRRRRTtget_insert_default(RR-tseq_namettabRVRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR^ s4    $$    cCs tj|S(N(tAUTOCOMMIT_REGEXPtmatch(RR}((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytshould_autocommit_text s(RRRVR^Rc(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRT s -t"PGReadOnlyConnectionCharacteristiccBs)eZeZdZdZdZRS(cCs|j|tdS(N(t set_readonlyR(RRt dbapi_conn((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytreset_characteristic scCs|j||dS(N(Re(RRRfR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytset_characteristic scCs |j|S(N(t get_readonly(RRRf((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_characteristic s(RRRt transactionalRgRhRj(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRd s  t$PGDeferrableConnectionCharacteristiccBs)eZeZdZdZdZRS(cCs|j|tdS(N(tset_deferrableR(RRRf((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRg scCs|j||dS(N(Rm(RRRfR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRh scCs |j|S(N(tget_deferrable(RRRf((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRj s(RRRRkRgRhRj(((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRl s  t PGDialectcBseZdZeZeZdZeZeZeZ eZ eZ eZ eZ eZeZeZeZeZeZeZdZeZeZeZeZeZeZ e!Z"e#Z$d?Z&eZ'eZ(e)j*j+Z+e+j,ie-d6e.d6Z+e/j0ied6d?d6d?d6id6ed 6id 6d?d 6fe/j1ied 6d?d 6d?d 6d?d6d?d6d?d6fe/j2ied6fe/j3ied6fgZ4d@Z5eZ6eZ7eZ8d?d?d?dZ9dZ:dZ;e<ddddgZ=dZ>dZ?dZ@dZAdZBdZCd ZDd!ZEeed"ZFeed#ZGd$ZHd%ZId&ZJd?d'ZKd?d(ZLd?d)ZMd*ZNeOjPd?d+ZQeOjPd,ZReOjPd?d-ZSeOjPd?d.ZTeOjPd?dAd1ZUeOjPd?d2ZVeOjPd?d3ZWeOjPd?d4ZXd5ZYeOjPd?d6ZZeOjPd?ed7Z[d8Z\eOjPd9Z]eOjPd?d:Z^eOjPd?d;Z_eOjPd?d<Z`d?d=Zad>ZbRS(BRi?tpyformattpostgresql_readonlytpostgresql_deferrableRhRRkRRRmRtignore_search_pathRRRRRtpostgresql_ignore_search_pathcKs2tjj||||_||_||_dS(N(R tDefaultDialectRtisolation_levelt_json_deserializert_json_serializer(RRvtjson_serializertjson_deserializerR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR` s  cCstt|j||jdkr8t|_|_n|jd k|_|js|jj |_|jj t j d|jj tdn|jd k|_|jd krt|_n$|jdj}|dk|_|jd k|_|jd k|_|jdk|_dS(Niiii s show standard_conforming_stringsRQi (ii(ii(i i(ii(ii(i i(i (RRot initializetserver_version_infoRtfull_returningtimplicit_returningRtcolspecstcopyRRRRRRRDtexec_driver_sqltscalarRRR(RRt std_string((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyR{p s&   cs*jdk r"fd}|SdSdS(Ncsj|jdS(N(tset_isolation_levelRv(RI(R(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytconnect s(RvR(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(NRRsLInvalid value '%s' for isolation_level. Valid isolation levels for %s are %ss, s=SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL %stCOMMIT( REt_isolation_lookupRt ArgumentErrorRRytcursorRtclose(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(RRtfetchoneRRN(RRRtval((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_isolation_level s    cCs tdS(N(tNotImplementedError(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRe scCs tdS(N(R(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRi scCs tdS(N(R(RRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRm scCs tdS(N(R(RR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRn scCs|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(RRRt 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(NRsCOMMIT PREPARED '%s'R(RRRt do_commit(RRRRR((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(RR R(RRt resultsettrow((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytdo_recover_twophase scCs|jdjS(Nsselect current_schema()(RR(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( RR Rt bindparamst bindparamR RRRtUnicodetbooltfirst(RRRtqueryR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt has_schema scCs|j||dkr[|jtjdjtjdtj|dt j }n`|jtjdjtjdtj|dt j tjdtj|dt j }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( t_ensure_has_table_connectionRRR RRRR RRRRR(RRRHRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt has_tables*     cCs|dkr|j}n|jtjdjtjdtj|dt j tjdtj|dt j }t |j S(NsSELECT relname FROM pg_class c join pg_namespace n on n.oid=c.relnamespace where relkind='S' and n.nspname=:schema and relname=:nameRRR( RRJRR RRRR RRRRR(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( RR RRRR RRRRRR(RRt type_nameRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRDs ! $cCs~|jdj}tjd|}|s@td|ntg|jdddD]}|dk rYt|^qYS(Nsselect pg_catalog.version()sQ.*(?:PostgreSQL|EnterpriseDB) (\d+)\.?(\d+)?(?:\.(\d+))?(?:\.\d+)?(?:devel|beta)?s,Could not determine version from string '%s'iii( RRR6RbtAssertionErrorRRCRtint(RRRtmtx((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_get_server_version_infofs c Ksd}|dk rd}nd}d|}tj|}|dk rXtj|}ntj|jdtj}|jdtj }|r|jtj ddtj}n|j |t d|d|} | j }|dkrtj|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') RHRRRN(RR RR RRRRRmtIntegerRRRRRtNoSuchTableError( RRRHRRt table_oidtschema_where_clauseRRrRe((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRGss$     $!  cKsA|jtjdjdtj}g|D]\}|^q.S(NsOSELECT nspname FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' ORDER BY nspnameR(RR RRmRR(RRRtresultR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_schema_namess  cKsb|jtjdjdtjtd|dk r9|n|j}g|D]\}|^qOS(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( RR RRmRRRRRJ(RRRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_table_namess  cKsb|jtjdjdtjtd|dk r9|n|j}g|D]\}|^qOS(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'RR( RR RRmRRRRRJ(RRRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRMs  RORPc Ksidd6dd6}y*gtj|D]}||^q'}Wn$tk rdtd|fnX|sztdn|jtjddjd |Djd t j t d |dk r|n|j }g|D]\} | ^qS( NRRORRPs_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((RAtelem((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys sRR(R tto_listtKeyErrort ValueErrorRR RRyRmRRRRRJ( RRRRRt include_kindR6tkindsRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRQs&*    cKsl|s|j}n|jtjdjtjdtj|dtj }g|D]}|d^qXS(NsrSELECT relname FROM pg_class c join pg_namespace n on n.oid=c.relnamespace where relkind='S' and n.nspname=:schemaRRi( RJRR RRRR RRR(RRRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_sequence_namess  cKsR|jtjdjdtjtd|dk r9|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( RR RRmRRRRRJ(RRRRRR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_view_definitions    c Kst|j|||d|jd}|jdkr9dnd}|jdkrWd}nd}d||f}tj|jtjd d tjj d tj d tj } |j | t d |} | j } |j|} t d |j|ddD} g}x]| D]U\}}}}}}}}|j||||| | |||| }|j|qW|S(NREi sa.attgenerated as generatedsNULL as generatedi s (SELECT json_build_object( 'always', a.attidentity = 'a', 'start', s.seqstart, 'increment', s.seqincrement, 'minvalue', s.seqmin, 'maxvalue', s.seqmax, 'cache', s.seqcache, 'cycle', s.seqcycle) FROM pg_catalog.pg_sequence s JOIN pg_catalog.pg_class c on s.seqrelid = c."oid" WHERE c.relkind = 'S' AND a.attidentity != '' AND s.seqrelid = pg_catalog.pg_get_serial_sequence( a.attrelid::regclass::text, a.attname )::regclass::oid ) as identity_options sNULL as identity_optionss 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.attrelid as table_oid, pgd.description as comment, %s, %s 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 RRtattnameR cssF|]<}|dr&|df|fn|d|df|fVqdS(tvisibleRRN((RAtrec((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys XsRt*(i (i (RGRR|R RRRRRRmRRRtfetchallt _load_domainsRKt_get_column_infoR(RRRHRRRRRtSQL_COLSRrRetrowstdomainsRRmRRtdefault_R}tcommentt column_info((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt get_columns sF    " c  Csqd} |dkr.t} d} }t}n-t} tjdd|} | | \} }ttj| }| }tjd|}|r|j d}ntjd|}|r|j drttj d|j d}nd2}i}| d krC|r:|j d \}}t |t |f}qd3}nT| d krXd4}n?| d krmd5}n*| d6krt|d<|rt ||dNcSs"tjdd||jdfS(Ns\[\]$R2s[](R6R7tendswith(tattype((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt_handle_array_typessno format_type()s\(.*\)R2s \(([\d,]+)\)is\((.*)\)s\s*,\s*Rt,sdouble precisioni5Rstimestamp with time zonestime with time zoneRRstimestamp without time zonestime without time zoneRs bit varyingRRs interval (.+)RRRRtlabelsRRR Rs6PostgreSQL format_type() returned NULL for column '%s's*Did not recognize type '%s' of column '%s'sRPRRrs(nextval\(')([^']+)('.*$)R?is"%s"iRt autoincrementRRR(((i5((stimestamp with time zonestime with time zone((stimestamp without time zonestime without time zoneR((((NR2s(RrRr(RRRR6R7RR tquoted_token_parsertsearchRCtsplitRt startswithRbtIt ischema_namesRRRtNULLTYPERt issubclassRR(RRRR R}RRRRRRRtno_format_typeRtis_arraytenum_or_domain_keyRtcharlentargsRtprectscalet field_matchRRtdomainRRRbtschR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRzs    $                                 ! >     c Ks |j|||d|jd}|jdkrLd|jdd}nd}tj|jdtj}|j |t d |}g|j D]} | d ^q} d } tj| jd tj}|j |t d |}|j } i| d 6| d6S(NREiisq 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 RRis SELECT conname FROM pg_catalog.pg_constraint r WHERE r.conrelid = :table_oid AND r.contype = 'p' ORDER BY 1 tconnametconstrained_columnsR(ii( RGRR|t _pg_index_anyR RRmRRRRRR( RRRHRRRtPK_SQLRRetrRt PK_CONS_SQLR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_pk_constraint1s # cKs_|j}|j|||d|jd}d}tjd} tj|jdtj dtj } |j | t d|} g} x| j D]\} }}tj | |j}|\ }}}}}}}}}}}}}|dk r|dkr tnt}ngtjd|D]}|j|^q%}|rg||jkr^|}q|}n9|r|j|}n!|dk r||kr|}n|j|}gtjd |D]}|j|^q}d d |fd |fd |fd|fd|fgD}i| d6|d6|d6|d6|d6|d6}| j|qW| S(NREs 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)+)?RtcondefR`t DEFERRABLEs\s*,\s*s\s*,\scSs7i|]-\}}|dk r|dkr||qS(s NO ACTIONN(R(RARR((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys s  tonupdatetondeleteRFR6RbRRtreferred_schematreferred_tabletreferred_columnstoptions(RRGRR6tcompileR RRmRRRRRRtgroupsRRRRR>RJR(RRRHRRtRRFRtFK_SQLtFK_REGEXRRetfkeysRRt conschemaRRRRRRRbRRR6RFRRtfkey_d((sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pytget_foreign_keysdsV  - +   +     csN|jd kr<ddjfdtddDSdfSdS( Niis(%s)s OR c3s"|]}d|fVqdS(s %s[%d] = %sN((RAtind(RVt compare_to(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys sii s %s = ANY(%s)(ii(R|Rytrange(RRVR((RVRsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyRs $c& s-|j|||d|jd}|jd/krd|jd0krKdnd|jd1krcdnd |jd2kr{d nd |jd d f}n"d|jd3krdnd f}tj|jdtjdtj}|j |t d|}t d} d} xs|j D]e} | \ } } }}}}}}}}}}|r| | krstjd| n| } qn| | k}| | }|dk r||d|>R2s;Skipped unsupported reflection of expression-based index %sRRtinciR7t nulls_lastt nulls_firsttsortingRftduplicates_constraintt=Rtbtreetamnametpostgresql_whereRt column_namestinclude_columnsc3s1|]'\}}dd||fVqdS(RRN((RAR6R(tidx(sV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pys stcolumn_sortingRtpostgresql_includetpostgresql_withtpostgresql_using(ii(ii(ii(ii(i i((R7(R (R (i i(RGRR|RR RRmRRRRRRRR RRRtstript enumerateRRR(&RRRHRRRtIDX_SQLRRetindexest sv_idx_nameRtidx_nameRfRRVtcol_numtconrelidtidx_keyt idx_optionRRtfilter_definitiont indnkeyattsthas_idxRtidx_keystinc_keysRR tcol_idxt col_flagst col_sortingtoptionRRR6tentry((RsV/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.pyt get_indexess! *        ))         ,  ),       cKs|j|||d|jd}d}tj|jdtj}|j|td|}t d} xB|j D]4} | | j } | j | d<| j | d| js    -  ( R                  ,B;