ó
¿b]c           @   sñ   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	 d d l
 m Z d d l m Z d d	 l m Z d Z d
 e	 f d     YZ e e d  Z d e f d     YZ d e f d     YZ d e f d     YZ d S(   i   (   t   exti   (   t   util(   t   schema(   t   _generative(   t   Insert(   t   ClauseElement(   t   alias(   t   public_factoryR   t   insertc           B   sV   e  Z d  Z e j d    Z e d d d d d d   Z e d d d d   Z	 RS(   s   PostgreSQL-specific implementation of INSERT.

    Adds methods for PG-specific syntaxes such as ON CONFLICT.

    .. versionadded:: 1.1

    c         C   s   t  |  j d d j S(   s  Provide the ``excluded`` namespace for an ON CONFLICT statement

        PG's ON CONFLICT clause allows reference to the row that would
        be inserted, known as ``excluded``.  This attribute provides
        all columns in this row to be referenceable.

        .. seealso::

            :ref:`postgresql_insert_on_conflict` - example of how
            to use :attr:`.Insert.excluded`

        t   namet   excluded(   R   t   tablet   columns(   t   self(    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyR
      s    c         C   s   t  | | | | |  |  _ |  S(   s  
        Specifies a DO UPDATE SET action for ON CONFLICT clause.

        Either the ``constraint`` or ``index_elements`` argument is
        required, but only one of these can be specified.

        :param constraint:
         The name of a unique or exclusion constraint on the table,
         or the constraint object itself if it has a .name attribute.

        :param index_elements:
         A sequence consisting of string column names, :class:`.Column`
         objects, or other column expression objects that will be used
         to infer a target index.

        :param index_where:
         Additional WHERE criterion that can be used to infer a
         conditional target index.

        :param set\_:
         Required argument. A dictionary or other mapping object
         with column names as keys and expressions or literals as values,
         specifying the ``SET`` actions to take.
         If the target :class:`.Column` specifies a ".key" attribute distinct
         from the column name, that key should be used.

         .. warning:: This dictionary does **not** take into account
            Python-specified default UPDATE values or generation functions,
            e.g. those specified using :paramref:`.Column.onupdate`.
            These values will not be exercised for an ON CONFLICT style of
            UPDATE, unless they are manually specified in the
            :paramref:`.Insert.on_conflict_do_update.set_` dictionary.

        :param where:
         Optional argument. If present, can be a literal SQL
         string or an acceptable expression for a ``WHERE`` clause
         that restricts the rows affected by ``DO UPDATE SET``. Rows
         not meeting the ``WHERE`` condition will not be updated
         (effectively a ``DO NOTHING`` for those rows).

         .. versionadded:: 1.1


        .. seealso::

            :ref:`postgresql_insert_on_conflict`

        (   t   OnConflictDoUpdatet   _post_values_clause(   R   t
   constraintt   index_elementst   index_wheret   set_t   where(    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyt   on_conflict_do_update.   s    9c         C   s   t  | | |  |  _ |  S(   s"  
        Specifies a DO NOTHING action for ON CONFLICT clause.

        The ``constraint`` and ``index_elements`` arguments
        are optional, but only one of these can be specified.

        :param constraint:
         The name of a unique or exclusion constraint on the table,
         or the constraint object itself if it has a .name attribute.

        :param index_elements:
         A sequence consisting of string column names, :class:`.Column`
         objects, or other column expression objects that will be used
         to infer a target index.

        :param index_where:
         Additional WHERE criterion that can be used to infer a
         conditional target index.

         .. versionadded:: 1.1

        .. seealso::

            :ref:`postgresql_insert_on_conflict`

        (   t   OnConflictDoNothingR   (   R   R   R   R   (    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyt   on_conflict_do_nothingl   s    N(
   t   __name__t
   __module__t   __doc__R   t   memoized_propertyR
   R   t   NoneR   R   (    (    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyR      s   7s   .dialects.postgresql.insertt   OnConflictClausec           B   s   e  Z d d d d   Z RS(   c         C   s  | d  k	 r[ t | t j  r[ t | t j t j t j f  r[ t	 | d  pR | } q[ n  | d  k	 r/| d  k	 r t
 d   n  t | t j  r² | |  _ d  |  _ d  |  _ q/t | t j  ræ | j } | j d j d  } q/t | t j  r| j } | j } q/| j } | j d j d  } n  | d  k	 rYd  |  _ | |  _ | |  _ n& | d  k rd  |  _ |  _ |  _ n  d  S(   NR	   s8   'constraint' and 'index_elements' are mutually exclusivet
   postgresqlR   (   R   t
   isinstanceR   t   string_typesR   t   Indext
   ConstraintR    t   ExcludeConstraintt   getattrt
   ValueErrort   constraint_targett   inferred_target_elementst   inferred_target_whereclauset   expressionst   dialect_optionst   getR   R   (   R   R   R   R   (    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyt   __init__   s:    							N(   R   R   R   R,   (    (    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyR      s   R   c           B   s   e  Z d  Z RS(   R   (   R   R   t   __visit_name__(    (    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyR   ¿   s   R   c           B   s&   e  Z d  Z d d d d d d  Z RS(   R   c         C   s³   t  t |   j d | d | d |  |  j d  k rR |  j d  k rR t d   n  t | t  si | rx t d   n  g  | j	   D] \ } } | | f ^ q |  _
 | |  _ d  S(   NR   R   R   sV   Either constraint or index_elements, but not both, must be specified unless DO NOTHINGs,   set parameter must be a non-empty dictionary(   t   superR   R,   R'   R   R&   R%   R   t   dictt   itemst   update_values_to_sett   update_whereclause(   R   R   R   R   R   R   t   keyt   value(    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyR,   Æ   s    .N(   R   R   R-   R   R,   (    (    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyR   Ã   s   N(   R   R   (   t    R    R   t   sqlR   t   sql.baseR   t   sql.dmlR   t   StandardInsertt   sql.elementsR   t   sql.expressionR   t   util.langhelpersR   t   __all__R   R   R   R   (    (    (    sA   lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/dml.pyt   <module>   s   {,