
    Ng0                      U d Z ddlmZ ddlZddlmZ ddlZddlm	Z	 ddl
Z
ddlZddlZddlZddlmZ ddl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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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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&m0Z0 dd&l&m1Z2 dd'l3m4Z4 dd(l3m5Z5 dd)l'm6Z6 dd*l'm7Z7 dd+l'm8Z8 dd,l'm9Z9 dd-l'm:Z: dd.l'm;Z; dd/l*m<Z< dd0l*m=Z= dd1l.m>Z> dd2l0m?Z? dd3l@mAZA dd4lBmCZC dd5lBmDZD d6d7l&mEZE d6d&l&m1Z1 d6d8l1mFZF d6d9lGmHZH d6d:lGmIZI d6d;lGmJZJ ej$        rdd<lKmLZL dd=l'mMZM dd>l'mNZN dd?lOmPZP dd@lQmRZR ddAlSmTZT ddBlSmUZU ddClSmVZV ddDl*mWZW ddEl*mXZX ddFl*mYZY ddGl*mZZZ ddHl*m[Z[ ddIl+m\Z\ ddJl.m]Z] ddKl/m^Z^ ddLl/m_Z_ ddMl/m`Z` ddNl/maZa ddOl/mbZb ddPl/mcZc ddQl/mdZd ddRl/meZe ddSl@mfZf d6dTlgmhZh d6dUlimjZj d6dVlimkZk d6dWlimlZl d6dXlimmZm d6dYlimnZn d6dZlimoZo d6d[limpZp d6d\limqZq d6d]limrZr ed^esf         Zth d_Zu ejv        d`ejw                  Zx ejv        daejw                  Zydb  ezddc          D             {                    ddg          Z| ejv        deejw                  Z} ejv        deejw                  Z~ ejv        dfejw                  Z ejv        dgej                  Z ejv        dhej                  ZdiZedjdkdldmdndoZi e,j        dpe,j        dqe,j        dre,j        dse,j        dte,j        due,j        dve,j        dwe,j        dxe,j        dye,j        dze,j        d{e,j        d|e,j        d}e,j        d~e,j        de,j        di e,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        de,j        diZe+j        de+j        de+j        de+j        de+j        de+j        de+j        de+j        de+j        de+j        de+j        de+j        de+j        de+j        diZded<   ddddddddddddddddZe/j        j        de/j        j        de/j        j        de/j        j        de/j        j        de/j        j        diZ G d de          Z G d deI          ZdZded<   dZded<   d6Zded<   dZded<    G d̄ deJ          Z G d΄ dedЬѦ          Z G d҄ de          Z G dԄ de          Z G dք de          Z G d؄ deF          Z G dڄ de	          Z G d܄ de	          Z eeզ          \  ZZZZ G dބ d ej        dddg                    Z G d d          Z G d de1j                  Z G d de-j        e         e*j                  Z G d de-j        e         e*j                  Z G d deݦ          Z G d de          Z G d deݦ          Z G d deߦ          Z G d de          Z G d deI          Z G d deI          Z G d d          ZdS )a]  Base SQL and DDL compiler implementations.

Classes provided include:

:class:`.compiler.SQLCompiler` - renders SQL
strings

:class:`.compiler.DDLCompiler` - renders DDL
(data definition language) strings

:class:`.compiler.GenericTypeCompiler` - renders
type specification strings.

To generate user-defined SQL strings, see
:doc:`/ext/compiler`.

    )annotationsN)IntEnum)perf_counter)Any)Callable)cast)ClassVar)Dict)	FrozenSet)Iterable)Iterator)List)Mapping)MutableMapping)
NamedTuple)NoReturn)Optional)Pattern)Sequence)Set)Tuple)Type)TYPE_CHECKING)Union   )base)	coercions)crud)elements)	functions)	operators)roles)schema)
selectable)sqltypes)utilis_column_element)is_dml)	_de_clone)_from_objects)
_NONE_NAME) _SentinelDefaultCharacterization)
Executable)NO_ARG)ClauseElement)quoted_name)Column)	TupleType)
TypeEngine)prefix_anon_map)	Visitable   )exc)FastIntFlag)Literal)Protocol)	TypedDict)_AnnotationDict)_AmbiguousTableNameMap)CompileState)CacheKey)ExecutableDDLElement)Insert)
UpdateBase)
ValuesBase)_truncated_label)BindParameter)ColumnClause)ColumnElement)Label)Function)Table)AliasedReturnsRows)CompoundSelectState)CTE)
FromClause)NamedFromClause)ReturnsRows)Select)SelectState)_BindProcessorType)CursorResultMetaData)_CoreSingleExecuteParams)_DBAPIAnyExecuteParams)_DBAPIMultiExecuteParams)_DBAPISingleExecuteParams)_ExecuteOptions)_GenericSetInputSizesType)_MutableCoreSingleExecuteParams)Dialect)SchemaTranslateMapTyperO   >^   asdoinisonortoallandanyascendfornewnotoffoldsetbothcaser   descelsefromfullintojoinleftlikenullonlysomethentrueuserwhenarraycheckcrossfalsegrantgroupilikeinnerlimitorderouterrighttableunionusingwherebinarycolumncreateexceptfreezehavingisnulloffsetselectuniqueanalyseanalyzebetweencollatedefaultforeignleadingnaturalnotnullplacingprimarysimilarverbosedistinctoverlapstrailing	initially	intersect	localtime	symmetric
asymmetric
constraint
deferrable
referencescurrent_datecurrent_rolecurrent_timecurrent_usersession_userauthorizationlocaltimestampcurrent_timestampz^[A-Z0-9_$]+$z^[A-Z0-9_ $]+$c                ,    h | ]}t          |          S  )str).0xs     S/var/www/html/ai-engine/env/lib/python3.11/site-packages/sqlalchemy/sql/compiler.py	<setcomp>r      s    ;;;c!ff;;;    
   $z5^(?:RESTRICT|CASCADE|SET NULL|NO ACTION|SET DEFAULT)$z^(?:DEFERRED|IMMEDIATE)$z%(?<![:\w\$\x5c]):([\w\$]+)(?![:\w\$])z\x5c(:[\w\$]*)(?![:\w\$])z%%(%(name)s)s?z%%sz:[_POSITION]z$[_POSITION]z	:%(name)s)pyformatqmarkformatnumericnumeric_dollarnamed AND z OR z + z * z -  % -z < z <= z != z > z >= z = z IS DISTINCT FROM z IS NOT DISTINCT FROM z || z MATCH z NOT MATCH z IN z NOT IN ,  FROM  AS  IS z IS NOT z	 COLLATE zEXISTS 	DISTINCT zNOT zANY zALL z DESCz ASCz NULLS FIRSTz NULLS LASTz ^ z | z & ~z << z >> coalesceCURRENT_DATECURRENT_TIMECURRENT_TIMESTAMPCURRENT_USER	LOCALTIMELOCALTIMESTAMPrandomsysdateSESSION_USERUSERCUBEROLLUPzGROUPING SETSzDict[Type[Function[Any]], str]	FUNCTIONSmonthdayyearsecondhourdoyminutequarterdowweekepochmillisecondsmicrosecondstimezone_hourtimezone_minute)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   UNIONz	UNION ALLEXCEPTz
EXCEPT ALL	INTERSECTzINTERSECT ALLc                  B    e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   d	S )
ResultColumnsEntrya  Tracks a column expression that is expected to be represented
    in the result rows for this statement.

    This normally refers to the columns clause of a SELECT statement
    but may also refer to a RETURNING clause, as well as for dialect-specific
    emulations.

    r   keynamenameTuple[Any, ...]objectsTypeEngine[Any]typeN__name__
__module____qualname____doc____annotations__r   r   r   r   r   [  sY           LLL;III%  r   r   c                      e Zd Zdd
ZdS )_ResultMapAppenderr   r   r   r   Sequence[Any]type_r   returnNonec                    d S Nr   selfr   r   r   r  s        r   __call__z_ResultMapAppender.__call__{  s	     sr   N)
r   r   r   r   r   r  r  r   r  r	  r   r   r  r  r   r   r   r  r  z  s(             r   r  z
Literal[0]RM_RENDERED_NAMEz
Literal[1]RM_NAMEz
Literal[2]
RM_OBJECTS   z
Literal[3]RM_TYPEc                  .    e Zd ZU ded<   ded<   ded<   dS )_BaseCompilerStackEntryzSet[FromClause]asfrom_fromscorrelate_fromsrQ   r$   Nr   r   r  r  r   r   r   r  r    s6         !!!!$$$$r   r  c                  B    e Zd ZU ded<   ded<   ded<   ded<   ded	<   d
S )_CompilerStackEntryr?   compile_stateboolneed_result_map_for_nestedneed_result_map_for_compoundrQ   select_0Select[Any]insert_from_selectNr  r   r   r   r  r    sN         $$$$&&&&######r   r  F)totalc                      e Zd ZU dZded<   	 ded<   	 ded<   	 ded	<   	 d
ed<   	 edd            Zedd            ZdS )ExpandedStatea  represents state to use when producing "expanded" and
    "post compile" bound parameters for a statement.

    "expanded" parameters are parameters that are generated at
    statement execution time to suit a number of parameters passed, the most
    prominent example being the individual elements inside of an IN expression.

    "post compile" parameters are parameters where the SQL literal value
    will be rendered into the SQL statement at execution time, rather than
    being passed as separate parameters to the driver.

    To create an :class:`.ExpandedState` instance, use the
    :meth:`.SQLCompiler.construct_expanded_state` method on any
    :class:`.SQLCompiler` instance.

    r   	statementrV   
parameters%Mapping[str, _BindProcessorType[Any]]
processorsOptional[Sequence[str]]positiontupzMapping[str, List[str]]parameter_expansionr  r   c                z      j         t          j        d          t           fd j         D                       S )zrTuple of positional parameters, for statements that were compiled
        using a positional paramstyle.

        Nz.statement does not use a positional paramstylec              3  2   K   | ]}j         |         V  d S r  r'  )r   keyr  s     r   	<genexpr>z6ExpandedState.positional_parameters.<locals>.<genexpr>  s*      FFcT_S)FFFFFFr   )r+  r8   InvalidRequestErrortupler  s   `r   positional_parametersz#ExpandedState.positional_parameters  sN     #)@   FFFFT5EFFFFFFr   c                    | j         S )z.synonym for :attr:`.ExpandedState.parameters`.r/  r4  s    r   additional_parametersz#ExpandedState.additional_parameters  s     r   N)r  r   )r  rV   )r   r   r  r  r  propertyr5  r7  r   r   r   r%  r%    s          " NNN=(((( 6555+(((( 1000 	G 	G 	G X	G    X  r   r%  c                      e Zd ZU dZded<   	 ded<   	 ded<   	 ded	<   	 d
Zded<   	 d
Zded<   	 dZded<   	 dZded<   	 dZ	ded<   	 d
Z
ded<   	 d
Zded<   dS )_InsertManyValuesa  represents state to use for executing an "insertmanyvalues" statement.

    The primary consumers of this object are the
    :meth:`.SQLCompiler._deliver_insertmanyvalues_batches` and
    :meth:`.DefaultDialect._deliver_insertmanyvalues_batches` methods.

    .. versionadded:: 2.0

    r  is_default_exprr   single_values_exprList[crud._CrudParamElementStr]insert_crud_paramsintnum_positional_params_countedFsort_by_parameter_orderincludes_upsert_behaviorsNOptional[Sequence[Column[Any]]]sentinel_columnsr   num_sentinel_columnsr*  sentinel_param_keysimplicit_sentinelembed_values_counter)r   r   r  r  r  rA  rB  rD  rE  rF  rG  rH  r   r   r   r:  r:    s          
  8777M&&&&
 %*)))) ',++++ 9=<<<< !"!!!! 487777  $####	 "'&&&&	 	r   r:  c                  x    e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   ded<   ded<   dS )_InsertManyValuesBatchas  represents an individual batch SQL statement for insertmanyvalues.

    This is passed through the
    :meth:`.SQLCompiler._deliver_insertmanyvalues_batches` and
    :meth:`.DefaultDialect._deliver_insertmanyvalues_batches` methods out
    to the :class:`.Connection` within the
    :meth:`.Connection._exec_insertmany_context` method.

    .. versionadded:: 2.0.10

    r   replaced_statementrW   replaced_parameters#Optional[_GenericSetInputSizesType]processed_setinputsizesz#Sequence[_DBAPISingleExecuteParams]batchzSequence[Tuple[Any, ...]]sentinel_valuesr?  current_batch_sizebatchnumtotal_batchesr  rows_sortedis_downgradedNr   r   r   r   rJ  rJ  N  s         
 
 ////@@@@........MMMr   rJ  c                  D    e Zd ZdZdZdZdZdZeez  ez  Zeez  Z	dZ
dZdS )	InsertmanyvaluesSentinelOptszcbitflag enum indicating styles of PK defaults
    which can work as implicit sentinel columns

    r   r7            @   N)r   r   r  r  NOT_SUPPORTEDAUTOINCREMENTIDENTITYSEQUENCEANY_AUTOINCREMENT_SUPPORTED_OR_NOTUSE_INSERT_FROM_SELECTRENDER_SELECT_COL_CASTSr   r   r   rW  rW  g  sX         
 MMHH%08;%(99 r   rW  c                      e Zd ZdZ	 dZ	 dZdS )CompilerStater   r   r7   N)r   r   r  	COMPILINGSTRING_APPLIEDNO_STATEMENTr   r   r   re  re  y  s-        I=N L r   re  c                  .    e Zd ZdZdZ	 dZ	 dZ	 eez  ZdS )Lintingzrepresent preferences for the 'SQL linting' feature.

    this feature currently includes support for flagging cartesian products
    in SQL statements.

    r   r   r7   N)r   r   r  r  
NO_LINTINGCOLLECT_CARTESIAN_PRODUCTSWARN_LINTINGFROM_LINTINGr   r   r   rj  rj    sG          J!" L2-<L r   rj  c                  "    e Zd ZdZddZddZdS )
FromLinterzKrepresents current state for the "cartesian product" detection
    feature.Nc                   | j         }|sdS t          | j                  }t          |          }||}|                    |           n|                                }t          j        |g          }|rs|rq|                                |                               fd|D             }|	                    fd|D                        |
                    |           |r|q|r||fS dS )NNNc                    h | ]}|v |	S r   r   r   edgenodes     r   r   z"FromLinter.lint.<locals>.<setcomp>  s    @@@$44<<<<<r   c              3  P   K   | ] }||                                         V  !d S r  )indexrt  s     r   r1  z"FromLinter.lint.<locals>.<genexpr>  s7      NNDTdjj&6&6"67NNNNNNr   )fromsrp   edgesremovepopcollectionsdequepopleftdiscard
extendleftdifference_update)	r  startry  rz  the_rest
start_withstack	to_removerv  s	           @r   lintzFromLinter.lint  s$   
 	:DJu::JOOJ''''!J!:,// 	/ 	/==??DT""" A@@@%@@@I NNNNINNNNNN##I...  	/ 	/   	Z'':r   SELECTc                                                       \  }}|r`|}|r^d}d                     fd|D                       }|                    || j        |                   }t	          j        |           d S d S d S )Nz{stmt_type} statement has a cartesian product between FROM element(s) {froms} and FROM element "{start}".  Apply join condition(s) between each element to resolve.r   c              3  :   K   | ]}d j         |          d V  dS )"N)ry  )r   from_r  s     r   r1  z"FromLinter.warn.<locals>.<genexpr>  sG       & &16,
5),,,& & & & & &r   )	stmt_typery  r  )r  rx   r   ry  r&   warn)r  r  r  r  ry  template	froms_strmessages   `       r   r  zFromLinter.warn  s    #yy{{*  	#E #7  !II & & & &:?& & &  	 #//'#*Z0 *   	'"""""%	# 	## #r   r  )r  )r   r   r  r  r  r  r   r   r   rp  rp    sG         # # # #J# # # # # #r   rp  ry  rz  c                      e Zd ZU dZdZded<   	 dZded<   	 ded	<   	 d
Zd
ZdZ	ded<   dZ
ded<   dZded<   ej        Zded<   	 ded<   ej        Zded<   dZded<   	 dZded<   	 dZded<   	 ded<   	 dd
 ej                    fd;d$Zd< fd'Zed(             Zd) Zd* Zed+             Zd=d0Zd>d1Z	 	 	 d?d@d9Zed:             Z xZ S )ACompileda  Represent a compiled SQL or DDL expression.

    The ``__str__`` method of the ``Compiled`` object should produce
    the actual text of the statement.  ``Compiled`` objects are
    specific to their underlying database dialect, and also may
    or may not be specific to the columns referenced within a
    particular set of bind parameters.  In no case should the
    ``Compiled`` object be dependent on the actual values of those
    bind parameters, even though it may reference those values as
    defaults.
    NOptional[ClauseElement]r&   r   stringre  stateFzOptional[CursorResultMetaData]_cached_metadataz"Optional[List[ResultColumnsEntry]]_result_columns Optional[SchemaTranslateMapType]schema_translate_maprZ   execution_optionsIdentifierPreparerpreparerr=   _annotationszOptional[CompileState]r  dml_compile_stateOptional[CacheKey]	cache_keyfloat	_gen_timedialectr]   render_schema_translater  compile_kwargsMapping[str, Any]c                6   || _         | j         j        | _        |r&|| _        | j                            |          | _        |t
          j        | _        || _        |j	        | _
        |j        | _        | j
        r*t          rt          |t                    sJ |j        | _         | j        | j        fi || _        |r%| j                            | j        |          | _        t
          j        | _        nt
          j        | _        t-                      | _        dS )a  Construct a new :class:`.Compiled` object.

        :param dialect: :class:`.Dialect` to compile against.

        :param statement: :class:`_expression.ClauseElement` to be compiled.

        :param schema_translate_map: dictionary of schema names to be
         translated when forming the resultant SQL

         .. seealso::

            :ref:`schema_translating`

        :param compile_kwargs: additional kwargs that will be
         passed to the initial call to :meth:`.Compiled.process`.


        N)r  identifier_preparerr  r  _with_schema_translatere  rf  r  r&  supports_executioncan_executer  r   
isinstancer.   _execution_optionsr  processr  _render_schema_translatesrg  rh  r   r  r  r  r&  r  r  r  s         r   __init__zCompiled.__init__;  s   4 8 	(<D% M@@$ DM  &0DJ&DN(;D ) 6D F  =%i<<<<<)2)E&&$,t~HHHHDK& "mEEK!5  '5DJJ&3DJ%r   r  r	  c                l    |                                   t                                                      S r  )_init_compiler_clssuper__init_subclass__)cls	__class__s    r   r  zCompiled.__init_subclass__s  s+       ww((***r   c                    d S r  r   r  s    r   r  zCompiled._init_compiler_clsw  s    r   c                p    | j         r|                    | ||          S t          j        | j                  r  )r  _execute_compiledr8   ObjectNotExecutableErrorr&  )r  
connectiondistilled_paramsr  s       r   _execute_on_connectionzCompiled._execute_on_connection{  sE      	?//&(9   .t~>>>r   c                H    t          j        | t          |                    |r  r8   UnsupportedCompilationErrorr   r  elementerrkws       r   visit_unsupported_compilationz&Compiled.visit_unsupported_compilation  s    -dDMMBBKr   c                    t                      )zReturn a Compiled that is capable of processing SQL expressions.

        If this compiler is one, it would likely just return 'self'.

        NotImplementedErrorr4  s    r   sql_compilerzCompiled.sql_compiler  s     "###r   objr6   kwargsr   c                     |j         | fi |S r  _compiler_dispatch)r  r  r  s      r   r  zCompiled.process  s    %s%d55f555r   c                :    | j         t          j        u r| j        S dS )z3Return the string text of the generated SQL or DDL.r  )r  re  rg  r  r4  s    r   __str__zCompiled.__str__  s!     :555;2r   Tparams"Optional[_CoreSingleExecuteParams]extracted_parameters&Optional[Sequence[BindParameter[Any]]]escape_names)Optional[_MutableCoreSingleExecuteParams]c                    t                      )zReturn the bind params for this compiled object.

        :param params: a dict of string/object pairs whose values will
                       override bind values compiled in to the
                       statement.
        r  r  r  r  r  s       r   construct_paramszCompiled.construct_params  s     "###r   c                *    |                                  S )z0Return the bind params for this compiled object.r  r4  s    r   r  zCompiled.params  s     $$&&&r   )
r  r]   r&  r  r  r  r  r  r  r  )r  r	  )r  r6   r  r   r  r   )r  r   NNTr  r  r  r  r  r  r  r  )!r   r   r  r  r&  r  r  is_sqlis_ddlr  r  r  r&   
EMPTY_DICTr  r  r  r  r  immutabledictr  r  classmethodr  r  r  r8  r  r  r  r  r  __classcell__r  s   @r   r  r    sE        
 
 *.I----F4-FF7;;;;;:>O>>>>=AAAAA)-8888
 !   $(OL3333,0M0000 154444	 %)I((((	  BF(-,>D,>,@,@6( 6( 6( 6( 6(p+ + + + + +   [? ? ?L L L $ $ X$6 6 6 6    6:GK!	$ $ $ $ $ ' ' X' ' ' ' 'r   r  c                  .    e Zd ZdZdZddZddZddZdS )TypeCompilerz2Produces DDL specification for TypeEngine objects.z	visit_\w+r  r]   c                    || _         d S r  )r  )r  r  s     r   r  zTypeCompiler.__init__  s    r   r  r   r  r   r  r   c                    |j         r*| j        j        |j         v r|j         | j        j                 } |j        | fi |S r  )_variant_mappingr  r   r  r  r  r  s      r   r  zTypeCompiler.process  sM    "	>!U%;;;*4<+<=E'u'33333r   r  r  	Exceptionr   c                .    t          j        | |          |r  )r8   r  r  s       r   r  z*TypeCompiler.visit_unsupported_compilation  s     -dG<<#Er   N)r  r]   )r  r   r  r   r  r   )r  r   r  r  r  r   r  r   )r   r   r  r  ensure_kwargr  r  r  r   r   r   r  r    sa        <<L   4 4 4 4F F F F F Fr   r  c                  T    e Zd ZdZdZdZd
dZed             Zed             Z	d Z
d	S )_CompileLabelz;lightweight label object which acts as an expression.Label.labelr  r   
_alt_namesr   c                8    || _         || _        |f|z   | _        d S r  r  )r  colr   	alt_namess       r   r  z_CompileLabel.__init__  s"    	&9,r   c                    | j         j        S r  r  	proxy_setr4  s    r   r  z_CompileLabel.proxy_set      |%%r   c                    | j         j        S r  r  r   r4  s    r   r   z_CompileLabel.type      |  r   c                    | S r  r   r  r  s     r   
self_groupz_CompileLabel.self_group      r   N)r   )r   r   r  r  __visit_name__	__slots__r  r8  r  r   r  r   r   r   r  r    s         FEN/I- - - -
 & & X& ! ! X!    r   r  c                  X    e Zd ZdZdZdZd Zed             Zed             Z	d Z
d Zd	S )
ilike_case_insensitivea  produce a wrapping element for a case-insensitive portion of
    an ILIKE construct.

    The construct usually renders the ``lower()`` function, but on
    PostgreSQL will pass silently with the assumption that "ILIKE"
    is being used.

    .. versionadded:: 2.0

    ilike_case_insensitive_operandr  
comparatorc                ,    || _         |j        | _        d S r  r  )r  r  s     r   r  zilike_case_insensitive.__init__  s    !,r   c                    | j         j        S r  r  r4  s    r   r  z ilike_case_insensitive.proxy_set  r  r   c                    | j         j        S r  r   r4  s    r   r   zilike_case_insensitive.type  r  r   c                    | S r  r   r  s     r   r  z!ilike_case_insensitive.self_group   r  r   c                P    t          | j                            |                    S r  )r	  r  _with_binary_element_type)r  r  s     r   r  z0ilike_case_insensitive._with_binary_element_type  s'    %L22599
 
 	
r   N)r   r   r  r  r  r  r  r8  r  r   r  r  r   r   r   r	  r	    s        	 	 6N'I- - - & & X& ! ! X!  
 
 
 
 
r   r	  c                     e Zd ZU dZeZ ej        ddddddddd          Zde	d	<   	 d
e	d<   de	d<   dZ
eZdZde	d<   dZde	d<   dZde	d<   	 de	d<   	 dZde	d<   	 dZde	d<   	 dZde	d<   	 dZde	d<   de	d<   	 de	d <   	 d!e	d"<   	 dZde	d#<   	 dZde	d$<   	 dZde	d%<   	 d&e	d'<   	 d&e	d(<   	 d&e	d)<   	 d*e	d+<   	 dZde	d,<   	 dZde	d-<   	 dZde	d.<   	 dZde	d/<   	 dZde	d0<   	 dZde	d1<   	 dZd2e	d3<   	 dZd4e	d5<   	 dZd6e	d7<   dZ d8e	d9<   dZ!d:e	d;<    e"            Z#d<e	d=<   	  e"            Z$d<e	d><   	 ej%        Z&d?e	d@<   	 dZ'	 dZ(	 dZ)dAe	dB<   	 dZ*d6e	dC<   	 dZ+d6e	dD<   dZ,d6e	dE<   dZ-de	dF<   dGe	dH<   dIe	dJ<   dKe	dL<   de	dM<    e.j/        dN          Z0 e.j/        dO          Z1 e.j/        e1j2         dPe0j2                   Z3e4dQ             Z5e4dR             Z6ddde7dfdbdbZ8e9dcdd            Z:ej;        ddde            Z<e9df             Z=e9dg             Z>e9dh             Z?ej@        dedj            ZAejB        dfdl            ZCeDjE        dm             ZFdn ZGdo ZHej@        dgdq            ZIdr ZJe9ds             ZK	 	 dhdidxZL	 	 	 	 	 	 djdkdZMejB        d             ZNe9d             ZO	 dldmdZP ejQ        d          d             ZRde	d<   ej@        dnd            ZSej@         ejQ        d          d                         ZTej@         ejQ        d          d                         ZUd ZVd ZWdldZXd ZY	 dldZZ	 dldZ[	 	 	 	 	 dodZ\d Z]d Z^	 	 	 	 dpdqdZ_d Z`d Zad Zbd Zcd Zdd ZedrdZf	 dsdZgd Zhd Zid Zjd Zkd Zld Zmd Znd Zod Zpd Zqd Zrd Zsd Ztd Zud Zvd Zwd Zx	 drdtdZyd Zzd Z{d Z|	 dudZ}d Z~dÄ Z	 dvdĄZdń ZdƄ ZdǄ ZdȄ ZdɄ Zdʄ Zd˄ Zd̄ Z	 drd̈́Zd΄ Z	 	 	 	 dwdτZdЄ Zdф Zd҄ Zdӄ ZdԄ Z	 dldՄZdք Zdׄ Zej@        d؄             Zdل Zdڄ Zdۄ Zd܄ Zd݄ Zdބ Zd߄ Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z	 	 	 	 	 dxdZd ZedfdZd Zd ZdydZdzdZ	 	 	 	 	 	 d{d|dZd Zddddd ej        d          fd}dZd Zd Z	 	 	 	 	 	 	 	 d~dZd Zd ZdldZd ZdudZd Zd Zdd Z	 drd!Z	 	 	 	 	 	 	 dd"ZĐd# ZŐd$ ZƐd% Zǐd& ZȐd' Zɐd(e	d)<   ej        s( ej        d* e"            fd+ e"            fg          Z	 dld,ZdZdae	d-<   	 	 	 	 	 	 	 	 dd.Zϐdd2ZАd3 Zѐd4 ZҐd5 Z	 	 dsd6ZԐd7 ZՐd8 Z֐d9 Zאd: Zؐd; ZِddAZڐdB Z	 	 	 ddCZ	 	 	 	 	 	 	 ddDZݐdudEZސdF Z ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        i          Ze                    ej        ej        i          ZddJZddVZ	 ddWZdX ZdY ZdZ Zdrd[Zd\ Zd] Zdrd^Zd_ Zd` Zda ZdS (  SQLCompilerz~Default implementation of :class:`.Compiled`.

    Compiles :class:`_expression.ClauseElement` objects into SQL strings.

    PAZC_)%():.[] zClassVar[Mapping[str, str]]bindname_escape_characterszClassVar[Pattern[str]]_bind_translate_re_bind_translate_charsTFr  isdeleteisinsertisupdatezOptional[List[Column[Any]]]	postfetchr   zSequence[Column[Any]]insert_prefetchupdate_prefetchN&Optional[Sequence[ColumnElement[Any]]]implicit_returningisplaintextzDict[str, BindParameter[Any]]bindszDict[BindParameter[Any], str]
bind_nameszList[_CompilerStackEntry]r  returning_precedes_values'render_table_with_column_in_update_fromansi_bind_rulesr   bindtemplatecompilation_bindtemplate_numeric_binds_identifier_charzList[ResultColumnsEntry]r  _textual_ordered_columns_ad_hoc_textual_ordered_columns_loose_column_name_matching_numeric_binds_render_postcompilezOptional[ExpandedState]_post_compile_expanded_stateOptional[str]_pre_expanded_stringOptional[List[str]]_pre_expanded_positiontupzOptional[_InsertManyValues]_insertmanyvaluesz!Optional[crud._CrudParamSequence]_insert_crud_paramszFrozenSet[BindParameter[Any]]literal_execute_paramspost_compile_paramszutil.immutabledict[str, str]escaped_bind_nameszbOptional[Tuple[Dict[BindParameter[Any], List[BindParameter[Any]]], Dict[str, BindParameter[Any]]]]_cache_key_bind_matchr+  _values_bindparam_visited_bindparaminlinez"Optional[MutableMapping[CTE, str]]cteszDict[Tuple[int, str], CTE]ctes_by_level_namez/Dict[CTE, Tuple[int, str, selectable._CTEOpts]]level_name_by_ctectes_recursivez"__\[POSTCOMPILE_(\S+?)(~~.+?~~)?\]z%\(([^)]+?)\)s|c                .    |                                   d S r  )_init_bind_translater  s    r   r  zSQLCompiler._init_compiler_cls2  s      """""r   c                    t          j        d                    | j                            }t          j        d| d          | _        | j        | _        d S )Nr  r  r   )reescaperx   r"  compiler#  r$  )r  regs     r   rP  z SQLCompiler._init_bind_translate6  sK    i >??@@!#JJJJ!7!7$'$B!!!r   r  r]   r&  r  r  r  column_keysr*  for_executemanylintingrj  _supporting_againstOptional[SQLCompiler]r  r   c                J   || _         || _        |r-d |d         D             }	d |d         D             }
|
|	f| _        || _        || _        i | _        t          j                    | _        g | _	        g | _
        |j        | _        | j        rD|j                            d          x| _        }|r|j        dk    rdnd| _        t           | _        nt$          |j                 | _        d| _        |j        p|j        | _        t-                      | _        i | _        i | _        t5          j        | ||fi | | j        s| j        s| j        rt>          rtA          |tB                    sJ | j        s| j        rUt>          rtA          |tD                    sJ |j#        rd	| _$        n(| j        r!| j        r| j%        j&        r|j'        rd	| _$        t$          |j                 | _(        |r;| j)        *                    d
 |j)        +                                D                        | j,        tZ          j.        u rn| j        r0| j        r| /                                 n| 0                                 | j1        r2| 2                    dd	          }| 3                    |d	           dS dS dS )a  Construct a new :class:`.SQLCompiler` object.

        :param dialect: :class:`.Dialect` to be used

        :param statement: :class:`_expression.ClauseElement` to be compiled

        :param column_keys:  a list of column names to be compiled into an
         INSERT or UPDATE statement.

        :param for_executemany: whether INSERT / UPDATE statements should
         expect that they are to be invoked in an "executemany" style,
         which may impact how the statement will be expected to return the
         values of defaults and autoincrement / sequences and similar.
         Depending on the backend and driver in use, support for retrieving
         these values may be disabled which means SQL expressions may
         be rendered inline, RETURNING may not be rendered, etc.

        :param kwargs: additional keyword arguments to be consumed by the
         superclass.

        c                    i | ]
}|j         |S r   r0  r   bs     r   
<dictcomp>z(SQLCompiler.__init__.<locals>.<dictcomp>a  s    333AE1333r   r   c                    i | ]}||gS r   r   r^  s     r   r`  z(SQLCompiler.__init__.<locals>.<dictcomp>b  s    111qAs111r   r   r   r   r  NTc                "    i | ]\  }}|d v	||S )>   r  r  r  
positionalr3  r:  r4  r   r   kvs      r   r`  z(SQLCompiler.__init__.<locals>.<dictcomp>  s@       1	 	 q	 	 	r   Fr  _no_postcompile)_populate_self)4rV  r  rF  rW  rX  r.  r&   column_dictr/  r  r  rc  
paramstyle
startswithr:  r5  _pyformat_templater4  BIND_TEMPLATESrJ  label_lengthmax_identifier_lengthr5   anon_maptruncated_names_truncated_countersr  r  r&  r'  r%  r   r  rC   rD   _inlinerI  r  insert_executemany_returning_return_defaultsr3  __dict__updateitemsr  re  rg  _process_numeric_process_positionalr;  r  #_process_parameters_for_postcompile)r  r  r&  r  rV  rW  rX  rY  r  cksmckbmnbr'  s                r   r  zSQLCompiler.__init__<  s6   @ '" 	633il333D11IaL111D*.D&
  / 
 *,, 
! ",? 		O'.'9'D'DY'O'OOD" "-1AAACCs 3 -?D)),:7;M,ND)	  AG$A 	 ()) <>35 $==f==== 	'DM 	'T] 	' 9!)Z88888} ' '  =%i<<<<<$ 	'"&DKK) '' A' &6	' #'DK*7+=> 	M    3 < B B D D    " :555 /& /))++++,,...' !22!&$( 3  

 88t 9      65 r   r  c                ,    | j         dS | j         j        S )a  When an INSERT is compiled with a single set of parameters inside
        a VALUES expression, the string is assigned here, where it can be
        used for insert batching schemes to rewrite the VALUES expression.

        .. versionadded:: 1.3.8

        .. versionchanged:: 2.0 This collection is no longer used by
           SQLAlchemy's built-in dialects, in favor of the currently
           internal ``_insertmanyvalues`` collection that is used only by
           :class:`.SQLCompiler`.

        N)rA  r<  r4  s    r   insert_single_values_exprz%SQLCompiler.insert_single_values_expr  s     !)4)<<r   c                    | j         r| j         S | j        *t          | j                  rd | j        j        D             S dS )a  The effective "returning" columns for INSERT, UPDATE or DELETE.

        This is either the so-called "implicit returning" columns which are
        calculated by the compiler on the fly, or those present based on what's
        present in ``self.statement._returning`` (expanded into individual
        columns using the ``._all_selected_columns`` attribute) i.e. those set
        explicitly using the :meth:`.UpdateBase.returning` method.

        .. versionadded:: 2.0

        Nc                0    g | ]}t          |          |S r   r'   r   cs     r   
<listcomp>z3SQLCompiler.effective_returning.<locals>.<listcomp>  s6       $Q''  r   )r,  r&  r)   _all_selected_columnsr4  s    r   effective_returningzSQLCompiler.effective_returning  s\     " 
	**^'F4>,B,B' =    4r   c                    | j         S )zVbackwards compatibility; returns the
        effective_returning collection.

        )r  r4  s    r   	returningzSQLCompiler.returning  s     ''r   c                n    	 | j         d         d         S # t          $ r}t          d          |d}~ww xY w)a  Return the current 'executable' that is being compiled.

        This is currently the :class:`_sql.Select`, :class:`_sql.Insert`,
        :class:`_sql.Update`, :class:`_sql.Delete`,
        :class:`_sql.CompoundSelect` object that is being compiled.
        Specifically it's assigned to the ``self.stack`` list of elements.

        When a statement like the above is being compiled, it normally
        is also assigned to the ``.statement`` attribute of the
        :class:`_sql.Compiler` object.   However, all SQL constructs are
        ultimately nestable, and this attribute should never be consulted
        by a ``visit_`` method, as it is not guaranteed to be assigned
        nor guaranteed to correspond to the current statement being compiled.

        .. versionadded:: 1.3.21

            For compatibility with previous versions, use the following
            recipe::

                statement = getattr(self, "current_executable", False)
                if statement is False:
                    statement = self.stack[-1]["selectable"]

            For versions 1.4 and above, ensure only .current_executable
            is used; the format of "self.stack" may change.


        r$   z$Compiler does not have a stack entryN)r  
IndexError)r  ies     r   current_executablezSQLCompiler.current_executable  sM    <	M:b>,// 	M 	M 	MCDD"L	Ms    
4/4c                T    t          | j                  t          | j                  z   S r  )listr)  r*  r4  s    r   prefetchzSQLCompiler.prefetch%  s#    D())D1E,F,FFFr   Dict[Any, Any]c                    i S r  r   r4  s    r   _global_attributeszSQLCompiler._global_attributes)  s    	r   MutableMapping[CTE, str]c                d    t          j                    }|| _        i | _        i | _        d| _        |S )zInitialize collections related to CTEs only if
        a CTE is located, to save on the overhead of
        these collections otherwise.

        F)r&   OrderedDictrJ  rK  rL  rM  )r  rJ  s     r   _init_cte_statezSQLCompiler._init_cte_state-  s:     *.)9););	 #% "$#r   c              #  @  K   | j         | j        }}g dc| _         | _        	 | j        r| j        d         }d|d<   nd}| j         | j        fV  |r|                    d           ||c| _         | _        dS # |r|                    d           ||c| _         | _        w xY w)z;special API to support the use case of 'nested result sets'Fr  Tr  N)r  r8  r  r|  )r  result_columnsordered_columnsentrys       r   _nested_resultzSQLCompiler._nested_resultE  s        ! ( 79%3d3	z 
26:233&(===== 8		6777 8D $"7"7"7  8		6777 8D $"7    s   ,A5 5(Bc                     j         rJ  j        t          j        u sJ  j        rJ  j        j        dk    rdn j        j        dk    sJ dg dfd	t          j         j	         j
                   _
         j        r^d
  j                                        D             t           j                  t                    k    sJ fdD              _         n _          j        rcg t          j         j	         j        j                  } fd j        j        D             } j                            ||           _        d S d S )Nr   %sr   r   mre.Match[str]r  r   c                    |                      d          }|r                    |           S                     |                      d                     |                      d          S )Nr   r7   r   )r   append)r  normal_bindplaceholder	positionss     r   find_positionz6SQLCompiler._process_positional.<locals>.find_positionj  sd    ''!**K "  ---""   ,,,wwqzz!r   c                    i | ]\  }}||	S r   r   rd  s      r   r`  z3SQLCompiler._process_positional.<locals>.<dictcomp>y  s    OOOtq!aOOOr   c                <    g | ]}                     ||          S r   get)r   r   reverse_escapes     r   r  z3SQLCompiler._process_positional.<locals>.<listcomp>{  s6          37""4..     r   c           
     ~    g | ]9}|d          |d         t          j        j        |d                   |d         f:S )r   r   r7   r  )rR  sub_positional_pattern)r   rf  r  r  s     r   r  z3SQLCompiler._process_positional.<locals>.<listcomp>  sZ     " " "  aDaDF43]AaDIIaD	" " "r   r<  r>  )r  r  r  r   )r+  r  re  rg  r:  r  rk  rR  r  r  r  rE  ry  lenrA  r<  r>  _replace)r  r<  r>  r  r  r  r  s   `  @@@@r   r{  zSQLCompiler._process_positional]  s   ####z]99999&&&&<"h..KK<*g5555K		" 	" 	" 	" 	" 	" 	" f$mT[
 
 " 	)OOt/F/L/L/N/NOOONt.//3~3F3FFFFF       ;D     D  )D! 	I!#(&9" "
" " " " " /B" " " &*%;%D%D#5#5 &E & &D"""%	 	r   c                ~   	  j         sJ  j        t          j        u sJ d}i 	 j        rW j        Pt          j         fd j        	                                D              j        	                                          }n j        	                                }|D ]A}|	v r j
        |         }| j        v s	| j        v rd 	|<   , j         | }|dz  }|	|<   B| _        t          	           _         j        rDt%          	          } fd	                                D             	t%          	          |k    sJ  j                            	fd j                   _         j        rH j        j        	z  }d  j        j        D             } j                            ||           _        d S d S )Nr   c              3  .   K   | ]}|j         v|V  d S r  )rG  )r   r   r  s     r   r1  z/SQLCompiler._process_numeric.<locals>.<genexpr>  s=        4#999 9999 r   c                N    i | ]!\  }}j                             ||          |"S r   )rE  r  )r   r   posr  s      r   r`  z0SQLCompiler._process_numeric.<locals>.<dictcomp>  sB       D# '++D$77  r   c                :    |                      d                   S Nr   r   r  	param_poss    r   <lambda>z.SQLCompiler._process_numeric.<locals>.<lambda>  s    i

+ r   c                >    g | ]}|d          |d         d|d         fS )r   r   r  r  r   )r   rf  s     r   r  z0SQLCompiler._process_numeric.<locals>.<listcomp>  s=     " " " 1qtT1Q4(" " "r   r  )r:  r  re  rg  rA  rG  	itertoolschainr/  valuesr.  rD  rC  r5  next_numeric_posr  r+  rE  r  ry  _pyformat_patternr  r  r<  r>  r  )
r  numr   	bind_namebindph
len_beforer<  r>  r  s
   `        @r   rz  zSQLCompiler._process_numeric  sZ   """"z]99999$&	! 	-d&<&H O    $ 6 6 8 8  
 &&(( EE O**,,E 	* 	*II%%:i(D0004666 (,	)$$;BSBBq')	)$$ #	??" 	0YJ   !*!2!2  I y>>Z//// ,00++++T[
 
 ! 	 &9 " "/B" " "
 &*%;%D%D#5#5	 &E & &D"""	 	r   VMutableMapping[str, Union[_BindProcessorType[Any], Sequence[_BindProcessorType[Any]]]]c                >     d  fd j         D             D             S )Nc                    i | ]
\  }}|||S r  r   )r   r0  values      r   r`  z0SQLCompiler._bind_processors.<locals>.<dictcomp>  s2     
 
 
U   # " !  r   c           	   3     K   | ]t}j         |         |j        j        s|j                            j                  n7t          fd t          t          |j                  j        D                       fV  udS )c              3  L   K   | ]}|                     j                  V  d S r  )_cached_bind_processorr  )r   	elem_typer  s     r   r1  z9SQLCompiler._bind_processors.<locals>.<genexpr>.<genexpr>  sG       # # ) &<<T\JJ# # # # # #r   N)	r/  r   _is_tuple_typer  r  r3  r   r3   types)r   	bindparamr  s     r   r1  z/SQLCompiler._bind_processors.<locals>.<genexpr>  s          OI.  )~<	==dlKKK" # # # #-1 )9>. .#	# # #       r   )r/  r4  s   `r   _bind_processorszSQLCompiler._bind_processors  sK    
 
    "&  
 
 
 	
r   c                2    t          | j                  dk    S r  )r  r  r4  s    r   is_subqueryzSQLCompiler.is_subquery  s    4:""r   c                    | S r  r   r4  s    r   r  zSQLCompiler.sql_compiler  s    r   r  r  r  r%  c                \    |                      ||d          }|                     |          S )aR  Return a new :class:`.ExpandedState` for a given parameter set.

        For queries that use "expanding" or other late-rendered parameters,
        this method will provide for both the finalized SQL string as well
        as the parameters that would be used for a particular parameter set.

        .. versionadded:: 2.0.0rc1

        Trg  )r  r|  )r  r  r  r'  s       r   construct_expanded_statez$SQLCompiler.construct_expanded_state  sD     **%  + 
 


 77
 
 	
r   r  r  _group_numberOptional[int]_checkrh  r\   c                   | j         r:|s8| j        J |st          | j        j                  S t	          j        d          |ot          | j                  }|rU| j        t	          j	        d          | j        d         }| j
        }	|	J |	\  }
fdt          ||          D             }nd}|ri }| j                                        D ]\  }}|r| j                            ||          n|}|j        |v r||j                 ||<   >||v r||         ||<   N|rG|j        r@|r t	          j        d|j        |fz  d          t	          j        d	|j        z  d          |r|                    ||          }n|}|j        r|j        ||<   |j        ||<   |S i }| j                                        D ]\  }}|r| j                            ||          n|}|rG|j        r@|r t	          j        d|j        |fz  d          t	          j        d	|j        z  d          |r|                    ||          }n|}|j        r|j        ||<   |j        ||<   |S )
z5return a dictionary of bind parameter keys and valuesNzcan't construct new parameters when render_postcompile is used; the statement is hard-linked to the original parameters.  Use construct_expanded_state to generate a new statement and parameters.zcThis compiled object has no original cache key; can't pass extracted_parameters to construct_paramsr   c                2    i | ]\  }}|         D ]}||S r   r   )r   r_  	extractedr  r~  s       r   r`  z0SQLCompiler.construct_params.<locals>.<dictcomp>G  sJ     " " " Ay G" "  i" " " "r   z@A value is required for bind parameter %r, in parameter group %dcd3x)codez)A value is required for bind parameter %r)r;  r<  dictr'  r8   r2  r  rE  r  CompileErrorrF  zipr/  ry  r  r0  requiredcallableeffective_valuer  )r  r  r  r  r  r  rh  has_escaped_namesorig_extracted
ckbm_tupler  resolved_extractedpdr  r   escaped_namevalue_paramr~  s                    @r   r  zSQLCompiler.construct_params  s    # 
	O 
	4@@@ D=HIII-4   )JT$2I-J-J 	& ~%&J  
 "&!23J))) GD!" " " "$'8L$M$M" " " "& K	B#'?#8#8#:#: %= %=	4 )D+//d;;;  =F**'-im'<B|$$V^^'-d|B|$$ =	 2 =$ !54(}m<= "(	    "5G'm,!'    * 0&8&<&<%y' ' '0 ) =+6+F<((+6+<<((IB#'?#8#8#:#: 9 9	4 )D+//d;;;   i0 $ !54(}m<= "(	    "5G'm,!'    & ,"4"8"8I"N"NKK"+K% 9'2'BB|$$'2'8B|$$Ir   c                $   | j         j        j        j        fdi }| j        }| j        D ]U}||v r|j        j        r/fdt          t          |j                  j
        D             ||<   B |j                  ||<   V|S )Nc                x    |                                                              }||vr|v r|S d S r  )_unwrapped_dialect_implget_dbapi_type)typdbtypedbapir  exclude_typesinclude_typess     r   lookup_typez<SQLCompiler._get_set_input_sizes_lookup.<locals>.lookup_type  sV    0099HHOOF ""*fM.I.I"*f.E.Etr   c                &    g | ]} |          S r   r   )r   r  r  s     r   r  z;SQLCompiler._get_set_input_sizes_lookup.<locals>.<listcomp>  s3     ) ) )  K$$) ) )r   )r  include_set_input_sizesexclude_set_input_sizesr  rC  r/  r   r  r   r3   r  )	r  
inputsizesrC  r  r  r  r  r  r  s	       @@@@@r   _get_set_input_sizes_lookupz'SQLCompiler._get_set_input_sizes_lookup  s    ,77
	 
	 
	 
	 
	 
	 
	 
	 
!%!< 
	D 
	DI222~, D) ) ) )#Iy~>>D) ) )
9%%
 )4IN(C(C
9%%r   c                .    |                      d          S )zReturn the bind param dictionary embedded into this
        compiled object, for those values that are present.

        .. seealso::

            :ref:`faq_sql_expression_string` - includes a usage example for
            debugging use cases.

        F)r  r  r4  s    r   r  zSQLCompiler.params  s     $$E$222r   r'  ri  c                0    i } j         }| j        } j        rg } j        }| j        }ndx}} j        }t          d|          t          d|          i }i i }	d}
 j        r||} j        rg }
n j        	                                } j
        }|D ]|r|                              n} j                 }| j        v r2|vr-                     ||                    |                    |<   e| j        v r|v r|	|         }d}n;|                              }                     |||          }|\  }}||	|<   ||<   |j        s|                    |           |j        j        r5|J |                    fdt-          |d          D                        n"|                    fd|D                        |
 |
                    d |D                        n!||                    d	 |D                        d
 |D             |<   ||                               fd}t3          j         j        ||          }|
X|J  fdt-          |
 j                  D              j                            fd|          }|                    |
           t=          |||||          }|rE| _         | _        |j         _         j        rtA          |j        pd          nd _        | _!        |S )a  handle special post compile parameters.

        These include:

        * "expanding" parameters -typically IN tuples that are rendered
          on a per-parameter basis for an otherwise fixed SQL statement string.

        * literal_binds compiled with the literal_execute flag.  Used for
          things like SQL Server "TOP N" where the driver does not accommodate
          N as a bound parameter.

        Nr(  z/Mapping[str, Sequence[_BindProcessorType[Any]]]render_literal_valuec              3     K   | ]M\  }}t          |d           D ]7\  }}v r.         |d z
           d|d|         |d z
           fV  8NdS )r   Nr  	enumerate)r   ituple_elementjr  r   tuple_processorss        r   r1  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>=  s       	. 	.
 !1=(1-(C(C	. 	. !%1#'777 0 6q1u = I /3ddAAAqq 9 0 6q1u = !J I I I I	. 	.r   r   c              3  :   K   | ]\  }}v 	|         fV  d S r  r   )r   r0  r  r   single_processorss      r   r1  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>H  sJ       . . &Q#'888 !"3D"9:8888. .r   c              3      K   | ]	\  }}|V  
d S r  r   r   r   r  s      r   r1  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>N  s7       3 3%,T1D3 3 3 3 3 3r   c              3      K   | ]	\  }}|V  
d S r  r   r  s      r   r1  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>U  s&      .M.Mat.M.M.M.M.M.Mr   c                    g | ]\  }}|S r   r   )r   
expand_keyr  s      r   r  zCSQLCompiler._process_parameters_for_postcompile.<locals>.<listcomp>V  s)     1 1 1'4z1
1 1 1r   c                L   |                      d          }|         }|                      d          rn|                      d                              d          }|d         |d         cd                    fd|                    d          D                       }|S )Nr   r7   ~~r  r   c              3  (   K   | ]}|V  d S r  r   )r   expbe_leftbe_rights     r   r1  z]SQLCompiler._process_parameters_for_postcompile.<locals>.process_expanding.<locals>.<genexpr>e  sD       ! ! !(hh7! ! ! ! ! !r   )r   splitrx   )r  r0  exprtokr  r  replacement_expressionss       @@r   process_expandingzJSQLCompiler._process_parameters_for_postcompile.<locals>.process_expanding\  s    ''!**C*3/D wwqzz ggajj&&t,,$'FCF!yy ! ! ! ! !#zz$//! ! !   Kr   c                .    i | ]\  }}|j          | S r   r5  )r   r  r0  r  s      r   r`  zCSQLCompiler._process_parameters_for_postcompile.<locals>.<dictcomp>q  s=       C ;BSBB  r   c                :    |                      d                   S r  r  r  s    r   r  zASQLCompiler._process_parameters_for_postcompile.<locals>.<lambda>y  s    )AGGAJJ/ r   r   )"r>  r  rc  r@  r+  r  r   r:  r/  r  rE  r  r.  rC  render_literal_bindparamr|  rD  $_literal_execute_expanding_parameterliteral_executerx  r   r  r  extendr  rR  r  _post_compile_patternr  r  r%  r&  r  r<  )r  r'  ri  expanded_parameterspre_expanded_stringnew_positiontuppre_expanded_positiontupr)  new_processorsto_update_setsnumeric_positiontupnamesebnr  	parameter	to_updater  leep_resreplacement_exprr  r&  expanded_stater   r  r  r
  r  s   `                     @@@@@r   r|  z/SQLCompiler._process_parameters_for_postcompile  s   $ ! #7&"&+? 	> O'+'E$'/+/+;( :>=O6*
 3Z
 
  =z
 
 >@24)+ 48? 	-7C#;E" )&(#O**,,E% I	- I	-D25?3774...4L
4(ID777'>>>55%1;1M1M 6   ,L9 D444#::: .| <I!FF (^^D11F#HH$i   H 5=1Y 03<N<0<L+L9 0 %%i000 ~4 %111&-- 	. 	. 	. 	. 	.
 5>fa4H4H	. 	. 	. 	 	 	 	 '-- . . . . .*3. . .   
 +6+22 3 3093 3 3     )4 (...M.M9.M.M.MMMM1 18A1 1 1'- !,&&t,,,	 	 	 	 	 F&(9;N
 
	 *"...    )')>! !  I .22//// I ""#6777&
 
  	? )<D%-ED*(2DK ?^/52666 
 1?D-r   zsqlalchemy.engine.cursorc                b    t           j        j        }|j                            | j                  S )z(utility method used for unit tests only.)r&   	preloadedengine_cursorrU   _create_description_match_mapr  )r  cursors     r   _create_result_mapzSQLCompiler._create_result_map  s/     -*HH 
 
 	
r   _BindNameForColProtocol_get_bind_name_for_colCallable[[Any], str]c                    | j         }|S r  )r8  )r  getters     r   _within_exec_param_key_getterz)SQLCompiler._within_exec_param_key_getter  s    ,r   zsqlalchemy.engine.resultc                  	
 t           j        j        }| j        | j        J | j        j        }t          rt          |t                    sJ |j	        }fd|j
        D             	d |j        <j                            | j        d           
           | j        v rfd}|nd 
|                    d |j
        D                       	
fd}|S )Nc                R    g | ]#}t          j        d  |          d          |f$S )r  N)operatormethodcaller)r   r  param_key_getters     r   r  zKSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.<listcomp>  sI     
 
 
 "5*:*:3*?*?FFL
 
 
r   c                <    |                     |           }||S | S r  r  )	lastrowidr'  param_valueautoinc_keys      r   _autoinc_getterzPSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>._autoinc_getter  s,    ",..i"H"HK".
  +*  )(r   c                    g | ]	}|j         
S r   r]  r   r  s     r   r  zKSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.<listcomp>      %K%K%K#cg%K%K%Kr   c                                    fdD                       S   fdD                       S )a  given cursor.lastrowid value and the parameters used for INSERT,
            return a "row" that represents the primary key, either by
            using the "lastrowid" or by extracting values from the parameters
            that were sent along with the INSERT.

            Nc              3  4   K   | ]\  }} |          V  d S r  r   )r   r;  r  r'  s      r   r1  zWSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get.<locals>.<genexpr>  s1      LL[VSffZ00LLLLLLr   c              3  \   K   | ]&\  }}|u r           nn
 |          V  'd S r  r   )r   r;  r  autoinc_colautoinc_getterrC  r'  s      r   r1  zWSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get.<locals>.<genexpr>  su         $ +--  .9 +N9jAAA!* $VJ//     r   r   )rC  r'  rM  rN  getterslastrowid_processorrow_fns   ``r   r  zDSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get  s     #.//	::	 vLLLLGLLLLLLv        (/     r   )r&   r2  engine_resultr<  r  r&  r   r  rB   r   primary_key_autoincrement_columnr   _cached_result_processorr  r.  result_tuple)r  resultr&  r   rF  r  rM  rN  rE  rO  rP  rA  rQ  s         @@@@@@@r   +_inserted_primary_key_from_lastrowid_getterz7SQLCompiler._inserted_primary_key_from_lastrowid_getter  s`    -=!---&0	 	1i00000
 
 
 
(
 
 

 1""-"2"K"Kd# # +*;77K dj((
) 
) 
) 
) 
) "1 #'$$%K%K9J%K%K%KLL	 	 	 	 	 	 	 	 	4 
r   c                  	 t           j        rddlm} nt          j        j        }| j        J | j        j        }t          rt          |t                    sJ | j        |j        }| j        }|J d t          |          D             t          dfd|j        D                       |                    d |j        D                       		fd}|S )Nr7   )rW  c                    i | ]\  }}||	S r   r   )r   idxr  s      r   r`  zKSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.<dictcomp>	  s    ===HCsC===r   z'List[Tuple[Callable[[Any], Any], bool]]c                    g | ]C}|v rt          j        |                   d fn t          j        d |          d          dfDS )Tr  NF)r?  
itemgetterr@  )r   r  rA  rets     r   r  zKSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.<listcomp>	  s|         czz (S22D99 !-!#3#3C#8#8$  		  r   c                    g | ]	}|j         
S r   r]  rH  s     r   r  zKSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.<listcomp>	  rI  r   c                8       fdD                       S )Nc              3  N   K   | ]\  }}|r |          n
 |          V   d S r  r   )r   r;  use_rowr'  rows      r   r1  zWSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get.<locals>.<genexpr>"	  sV        #FG  '>sFF:,>,>     r   r   )rc  r'  rO  rQ  s   ``r   r  zDSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get!	  sD    6     '.     r   )typingr   enginerW  r&   r2  rR  r  r&  r  rB   r<  r   r,  r  r   rS  rV  )
r  rW  r&  r   r  r  rO  rA  r^  rQ  s
         @@@@r   +_inserted_primary_key_from_returning_getterz7SQLCompiler._inserted_primary_key_from_returning_getter  s7     	2'''''''^1F!---&0	 	1i00000=+	$$$==	)(<(<===5     !,  
 
" $$%K%K9J%K%K%KLL	 	 	 	 	 	 
r   c                    dS )zCalled when a SELECT statement has no froms, and no FROM clause is
        to be appended.

        Gives Oracle a chance to tack on a ``FROM DUAL`` to the string output.

        r  r   r4  s    r   default_fromzSQLCompiler.default_from)	  s	     rr   c                H    |j         j        | fi |}|j        D ]}|| j        vr| j        |         }|                    |j        |j                 dd          }| j        |         }|x| j        |<   | j        |<   || j        |<   | j                            |d           || j        v r| xj        |hz  c_        || j	        v r| xj	        |hz  c_	        | j
        }|r@|\  }	}
|j        D ]3}|j        |
v r(|
|j                 }|	|                             |           4|S )a  SQL compile the nested element of an _OverrideBinds with
        bindparams swapped out.

        The _OverrideBinds is not normally expected to be compiled; it
        is meant to be used when an already cached statement is to be used,
        the compilation was already performed, and only the bound params should
        be swapped in at execution time.

        However, there are test cases that exericise this object, and
        additionally the ORM subquery loader is known to feed in expressions
        which include this construct into new queries (discovered in #11173),
        so it has to do the right thing at compile time as well.

        TF)maintain_keyr  N)r  r  	translater.  _with_valuer0  r/  r|  rD  rC  rF  _cloned_setr  )r  override_bindsr  sqltextre  bpnew_bpr   r  r~  r}  cbs               r   visit_override_bindsz SQLCompiler.visit_override_binds2	  sk   " <.(;DGGBGG  ) "	0 "	0A
""AB ^^(0! $  F ?2&D/55DJqMDJt,&*DOF#OD)))T---((VH4((T000++x7++3J 0'
d. 0 0Bv~~!"&\R///r   c                4    d |j         j        | fi |z   dz   S Nr  r  r  r  )r  groupingasfromr  s       r   visit_groupingzSQLCompiler.visit_groupingr	  +    8X%8HHHHH3NNr   c                4    d |j         j        | fi |z   dz   S ru  rv  )r  rw  r  s      r   visit_select_statement_groupingz+SQLCompiler.visit_select_statement_groupingu	  rz  r   c                   | j         r| j        j        r	 t          d| j         d         d                   }n'# t          $ r}t          j        d          |d }~ww xY w|j        \  }}}|r|}	n|}	|j        j	        }
|
8|
j
        |	v r/|
                    |	|
j
                           r|j        j	        |d<    | j        |j        fd|i|S )N'Union[SelectState, CompoundSelectState]r  r  ECan't resolve label reference for ORDER BY / GROUP BY / DISTINCT etc.render_label_as_labelwithin_columns_clause)r  r  supports_simple_order_by_labelr   KeyErrorr8   r  _label_resolve_dictr  _order_by_label_elementr   shares_lineager  )r  r  r  r  r  ke	with_cols
only_froms	only_colsresolve_dictorder_by_elems              r   visit_label_referencez!SQLCompiler.visit_label_referencex	  s9    : %	$,E %		 $=JrN?3! !    &/   1	$ ))( $OCM )!&,66!00 !34  7 O; ./ t|O
 
"7
 
 
 	
s   !7 
AAAc                    | j         s|                     |j                  S 	 t          d| j         d         d                   }n># t          $ r1}t          j        |j        dt          j	        |           Y d }~nd }~ww xY w|j
        \  }}}	 |r||j                 }	n||j                 }	|	|d<    | j        |	fd|i|S # t          $ r2}
t          j        |j        dt          j	        |
           Y d }
~
d S d }
~
ww xY w)Nr~  r  r  r  )extraexc_clsr  r  r  )r  r  _text_clauser   r  r   _no_text_coercionr  r8   r  r  )r  r  r  r  r  r  r  r  r  r  r  s              r   visit_textual_label_referencez)SQLCompiler.visit_textual_label_reference	  s    z 	6<< 4555	 9
2/ MM  		 		 		'/ (        		 ,9+L(	:y	$ 1 10 /2F*+4< +@DJ    		 		 		'/ (         		s/   !A 
B 'A;;B C 
C='C88C=c                   |o| }||u }	|	s|rBt          |j        t          j                  r|                     d|j                  }
n|j        }
|rq|% ||
|j        ||
f|j        z   |z   |j                    |j        j        | fddd|t          t          j                 z   | j                            ||
          z   S |	r| j                            ||
          S  |j        j        | fddi|S )NcolidentT)r  within_label_clauser  F)r  r   r   rE   _truncated_identifierr  r   r  r  	OPERATORSr!   as_r  format_label)r  r  add_to_result_mapr  r  r  result_map_targetsr  render_label_with_asrender_label_only	labelnames              r   visit_labelzSQLCompiler.visit_label	  sg    "=*=&= 	 2U: 	' 4 	'%*h&?@@ ' 66z5:NN		!J	 	 ,!!JI&)99<NNJ	   10*.(,  	  IM*+ -,,UI>>?	  	=--eY???35=3 ,157  r   c                *    t          j        d          )Nz:Cannot compile Column object until its 'name' is assigned.r8   r  r  r   s     r   _fallback_column_namez!SQLCompiler._fallback_column_name
  s    H
 
 	
r   c                ,    |j         } | j        |fi |S r  )	_resolvedr  )r  r  r  sql_elements       r   visit_lambda_elementz SQLCompiler.visit_lambda_element

  s$    't|K..2...r   r   ColumnClause[Any]r  Optional[_ResultMapAppender]include_tabler  r   ambiguous_table_name_map Optional[_AmbiguousTableNameMap]c                0   |j         x}}||                     |          }|j        }	|	s0t          |t          j                  r|                     d|          }|2|||j        f|z   }
|j        r|
|j        fz  }
 ||||
|j	                   |	r| 
                    |          }n| j                            |          }|j        }|	|r|j        s|S | j                            |          }|r| j                            |          dz   }nd}t"          rt          |t$                    sJ |j         }|s|r||v r||         }t          |t          j                  r|                     d|          }|| j                            |          z   dz   |z   S )Nr  r  r  alias)r   r  
is_literalr  r   rE   r  r0  	_tq_labelr   escape_literal_columnr  quoter   named_with_columnschema_for_objectquote_schemar   rP   )r  r   r  r  r  r  r  r   	orig_namer  targetsr   effective_schemaschema_prefix	tablenames                  r   visit_columnzSQLCompiler.visit_column
  s    ";&y<--f55D&
 	@jx/HII 	@--j$??D(tVZ03EEG /F,..dIwDDD 	- --d33DD=&&t,,D==U5L=K#}>>uEE #M../?@@3F  !# :!%99999
I %@,@ !9994Y?	)X%>?? K 66w	JJ	 4=#6#6y#A#AACG$NNr   c                @    | j                             |j                  S r  )r  format_collation	collationr  r  r  s      r   visit_collationzSQLCompiler.visit_collationI
  s    }--g.?@@@r   c                    |j         S r  r   )r  
fromclauser  s      r   visit_fromclausezSQLCompiler.visit_fromclauseL
  s
    r   c                    |j         S r  r  )r  rx  r  s      r   visit_indexzSQLCompiler.visit_indexO
  s
    zr   c                Z    ||d<   | j         |d<    | j        j        j        |j        fi |S )Ntype_expressionr  )r  r  type_compiler_instancer  r   )r  
typeclauser  s      r   visit_typeclausezSQLCompiler.visit_typeclauseR
  sH     *$(M !:t|2:O
 
!
 
 	
r   c                J    | j         j        r|                    dd          }|S Nr  %%r  _double_percentsreplacer  texts     r   post_process_textzSQLCompiler.post_process_textY
  '    =) 	+<<T**Dr   c                J    | j         j        r|                    dd          }|S r  r  r  s     r   r  z!SQLCompiler.escape_literal_column^
  r  r   c           	          fd} j         sd _        |r |d d ft          j                   t                              d t                              |                     j                                      S )Nc                    |                      d          }|j        v r j        j        |         fi S  j        |fi S r  )r   _bindparamsr  bindparam_string)r  r   r  r  
textclauses     r   do_bindparamz2SQLCompiler.visit_textclause.<locals>.do_bindparamd
  s]    771::Dz---#t|J$:4$@GGBGGG,t,T88R888r   Tc                ,    |                      d          S r  r  )r  s    r   r  z.SQLCompiler.visit_textclause.<locals>.<lambda>v
  s    aggajj r   )	r  r-  r%   NULLTYPEBIND_PARAMS_ESCr  BIND_PARAMSr  r  )r  r  r  r  r  s   `` ` r   visit_textclausezSQLCompiler.visit_textclausec
  s    	9 	9 	9 	9 	9 	9 	9 z 	$#D 	L dD:-9JKKK ""  OOd44Z_EE 
 
 	
r   c                   | j          }|r| j        n| j         d         }t                      t                      |d}| j                             |           |j        r|                     ||           |p1|dk    o|                    dd          p|                    dd          }|r[|j        x| _        | _	        |j         ot          |j                  | _        |j        D ]}	|                     |	d| j                     | j        |j        fi |}
| j        r1|st#          | j                   nd }|                     |	          |
z   }
| j                             d           |
S )
Nr  r  r  r$   r   r  Fr  T)r  r  nesting_level)r  _default_stack_entryrp   r  _independent_ctes_dispatch_independent_ctesr  rc  r8  r6  r  column_argsr9  r  _add_to_result_mapr  rJ  r  _render_cte_clauser|  )r  tafcompound_indexrx  r  toplevelr  	new_entrypopulate_result_mapr  r  r  s               r   visit_textual_selectz SQLCompiler.visit_textual_select|
  s    z>-5I))4:b>  #uuEE*
 *
	
 	
)$$$  	5++C444  >!# EII<eDD>
 yy5u== 	  	D!D$A 47>/A 0dG GD, _  *.&*&=      t|CK..2..9 	O3;EC
OOOM***GG$ND
rr   c                    dS NNULLr   r  r  r  s      r   
visit_nullzSQLCompiler.visit_null
      vr   c                "    | j         j        rdS dS )Nr   1r  supports_native_booleanr  s      r   
visit_truezSQLCompiler.visit_true
  s    </ 	63r   c                "    | j         j        rdS dS )Nr   0r  r  s      r   visit_falsezSQLCompiler.visit_false
  s    </ 	73r   c                ^     |                     d  fd|D             D                       S )Nc              3     K   | ]}||V  	d S r  r   r   ss     r   r1  z7SQLCompiler._generate_delimited_list.<locals>.<genexpr>
  s<       
 


 
 
 
 
 
r   c              3  4   K   | ]} |j         fi V  d S r  r  r   r  r  r  s     r   r1  z7SQLCompiler._generate_delimited_list.<locals>.<genexpr>
  s9      II1*a*466266IIIIIIr   rx   )r  r   	separatorr  s   `  `r   _generate_delimited_listz$SQLCompiler._generate_delimited_list
  sM    ~~ 
 
IIIIIIII
 
 
 
 
 	
r   c                Z    t           j                            t          j        t           j        j        t           j        j        |          \  }}|dk    r |d         j         fi S t          t          j                 }|
                    d  fd|D             D                       S )Nr   r   c              3     K   | ]}||V  	d S r  r   r  s     r   r1  z;SQLCompiler._generate_delimited_and_list.<locals>.<genexpr>
  s<       " """ " " " " "r   c              3  4   K   | ]} |j         fi V  d S r  r  r  s     r   r1  z;SQLCompiler._generate_delimited_and_list.<locals>.<genexpr>
  s9      LLq.!.t::r::LLLLLLr   )r   BooleanClauseList_process_clauses_for_booleanr!   and_True_
_singletonFalse_r  r  rx   )r  clausesr  lccr  s   ` `  r   _generate_delimited_and_listz(SQLCompiler._generate_delimited_and_list
  s    1NNNN%O&	
 
W !88071:0<<<<<!).1I>> " "LLLLLGLLL" " "   r   c                $    d | j         |fi |z  S N(%s))visit_clauselist)r  
clauselistr  s      r   visit_tuplezSQLCompiler.visit_tuple
  s#    --j??B????r   c                f    |j         }|d}nt          |j                  } | j        |j        |fi |S Nr!  )r?  r  r	  r  )r  r  r  seps       r   r  zSQLCompiler.visit_clauselist
  sC    !;CCJ/0C,t,Z-?KKKKKr   c                    |j         }|                     |dd           }|r
 |||fi |S 	 t          |         }d|d<    | j        |j        |fi |S # t
          $ r}t          j        | |          |d }~ww xY w)Nexpression_clauselistT_in_operator_expression)r?  _get_operator_dispatchr  r	  r  r  r8   r  )r  r  r  	operator_dispopstringr  s          r   visit_expression_clauselistz'SQLCompiler.visit_expression_clauselist
  s    '	**.
 
  	54
I44444	 +H -1B()040"H 02  	  	L 	L 	L1$	BBK	Ls   A 
A7A22A7c                   d}|j         | |j         j        | fi |dz   z  }|j        D ].\  }}|d |j        | fi |z   dz    |j        | fi |z   dz   z  }/|j        |d |j        j        | fi |z   dz   z  }|dz  }|S )NzCASE r!  zWHEN z THEN zELSE END)r  r  whenselse_)r  clauser  r   condrW  s         r   
visit_casezSQLCompiler.visit_case
  s    <#00@@@@3FFA"L 	 	LD&)$)$99&99: ,&+D;;F;;< 	AA <#9&,9$II&IIICOA 	
U
r   c                (     |j         j        | fi |S r  )typed_expressionr  )r  type_coercer  s      r   visit_type_coercezSQLCompiler.visit_type_coerce	  s     >{+>tJJrJJJr   c                     |j         j        | fi |}t          j        d|          }d |j        j        | fi |d|r|                    d          n|d|r|                    d          ndS )Nz(.*)( COLLATE .*)zCAST(r   r   r  r7   r  )r  r  rR  matchr+  r   )r  r   r  type_clauser3  s        r   
visit_castzSQLCompiler.visit_cast  s    8do8HHHH,k::*DK*4::6::::#4EKKNNN44#+EKKNNN+
 	
r   c           
     d   |d         t           j        u rdn|d         t           j        u rdnj|d         dk     r6 | j        t          j        t          |d                             fi |dn( | j        t          j        |d                   fi |dd|d         t           j        u rdn|d         t           j        u rdnj|d         dk     r6 | j        t          j        t          |d                             fi |dn( | j        t          j        |d                   fi |dS )	Nr   zUNBOUNDED PRECEDINGzCURRENT ROWz
 PRECEDINGz
 FOLLOWINGr   r   zUNBOUNDED FOLLOWING)r   RANGE_UNBOUNDEDRANGE_CURRENTr  literalabs)r  range_r  s      r   _format_frame_clausez SQLCompiler._format_frame_clause  s    !9 888 &% ayH$::: "M "!9q==	 )DL ( 0VAY @ @ DF     (4<(8(C(CJJrJJJJM ( !9 888 &% ayH$::: "M "!9q==	 )DL ( 0VAY @ @ DF     (4<(8(C(CJJrJJJJM+'
 '	
r   c                (     |j         j         fi }|j        rd  j        |j        fi z  }n |j        rd  j        |j        fi z  }nd }|dd                     fdd|j        fd|j        ffD             |r|gng z             dS )	NzRANGE BETWEEN %szROWS BETWEEN %sz OVER (r!  c           	     ^    g | ])\  }}|t          |          |d |j        fi *S )Nz BY )r  r  )r   wordr+  r  r  s      r   r  z*SQLCompiler.visit_over.<locals>.<listcomp>O  sc        %f )c&kk) tt6V6tFFvFFFH *))r   	PARTITIONORDERr  )r  r  r;  r<  rowsrx   partition_byorder_by)r  overr  r  r;  s   ` `  r   
visit_overzSQLCompiler.visit_over?  s$   .t|.t>>v>>; 		'*C$*C+ +%+ + FF Y 	&)B)B	* *#* * FF F DDHH     %d&78 $-0)    &-F882	/   
 	
r   c                V     |j         j        | fi |d |j        j        | fi |dS )Nz WITHIN GROUP (ORDER BY r  )r  r  rD  )r  withingroupr  s      r   visit_withingroupzSQLCompiler.visit_withingroup\  sN    2K24BB6BBBB3K 3DCCFCCCC
 	
r   c                V     |j         j        | fi |d |j        j        | fi |dS )Nz FILTER (WHERE r  )funcr  	criterion)r  
funcfilterr  s      r   visit_funcfilterzSQLCompiler.visit_funcfilterb  sM    .JO.t>>v>>>>3J 3DCCFCCCC
 	
r   c                    | j                             |j        |j                  }d|d |j        j        | fi |dS )NzEXTRACT(r   r  )extract_mapr  fieldr  r  )r  extractr  rQ  s       r   visit_extractzSQLCompiler.visit_extracth  sQ     $$W]GMBBEE+GL+D;;F;;;;
 	
r   c                T     | j         |j        fi |} | j        |fi |}d|d|S )Nr  z).)visit_functionfnr  )r  r  r  compiled_fncompiled_cols        r   visit_scalar_function_columnz(SQLCompiler.visit_scalar_function_columno  sK    )d)'*;;;;(t(77B77'KK66r   rK  Function[Any]c                    |# ||j         |j         |j         f|j                   t           d|j                                         z  d           }|r
 ||fi |}nt                              |                                j        d           r|j        rdz  n\|j          j	        
                              st          t          j                  r j	                                      ndz   d                     fd|j        D             gz             d  j        |fi |iz  }|j        r|dz  }|S )Nzvisit_%s_funcz%(expr)sr  c                    g | ]R}j                             |          st          t          j                  rj                             |          n|SS r   )r  _requires_quotes_illegal_charsr  r   r1   r  )r   r  r   r  s     r   r  z.SQLCompiler.visit_function.<locals>.<listcomp>  so        	  =GGLL!%dH,@AA!++C000 !  r   r  z WITH ORDINALITY)r   r   getattrlowerr   r  _deannotater  	_has_argsr  r]  r  r   r1   r  rx   packagenamesfunction_argspec_with_ordinality)r  rK  r  r  r$  r  r   s   `     @r   rU  zSQLCompiler.visit_functiont  s    (diTYL$)LLLt_ty/@/@@$GG  	@4''''DD==!1!1!3!3!=tDDD )> 'J&Dy }CCDII!$(<==DM''--- 	  j(88      $0   &	  ..t>>v>>?@D   	'&&Dr   c                6    |                      |j                  S r  )visit_sequencesequence)r  
next_valuer  s      r   visit_next_value_funcz!SQLCompiler.visit_next_value_func  s    "":#6777r   c                :    t          d| j        j        z            )Nz2Dialect '%s' does not support sequence increments.r  r  r   r  rg  r  s      r   rf  zSQLCompiler.visit_sequence  s$    !@l 
 
 	
r   c                (     |j         j        | fi |S r  )clause_exprr  )r  rK  r  s      r   rc  zSQLCompiler.function_argspec  s     2t24BB6BBBr   c           
     H     j          } |j        | fi }|r j        s| _        |j        }|r j        n j         d         }|p| o|                    dd          }	|dk    r||d<    j                             |d         |d         |||	d           |j        r                     |            j	        |j
                 }
d	|
z   d	z                        fd
t          |j                  D                       }dd<   |  j        |fi t          ddiz  }|  j        |fi z  }|j        r|  j        |fi z  } j        r2|st)           j                   nd }                     |d          |z   } j                             d           |S )Nr  r  Fr   r   r  r  )r  r  r$   r  r  r!  c              3  @   K   | ]\  }} |j         f|d V  dS ))rx  r  Nr  )r   r  r  rx  r  r  s      r   r1  z4SQLCompiler.visit_compound_select.<locals>.<genexpr>  sf         Aq %$!' =C      r   r  rx  Tr  include_following_stackr   )r  _compile_state_factoryr  r&  r  r  r  r  r  compound_keywordskeywordrx   r  selectsgroup_by_clauser  order_by_clause_has_row_limiting_clause_row_limit_clauserJ  r  r  r|  )r  csrx  r  r  r  r  compound_stmtr  need_result_mapru  r  r  s   ` ` `        r   visit_compound_selectz!SQLCompiler.visit_compound_select  se    z>11"dEEfEE 	/D. 	/!.D%/-5I))4:b>" 
 A		8%@@ 	 Q "E*
#():#; %n 5 !.0? 	
 	
 	
 * 	C++M6BBB(4g#))      &bj11	  
 
 #($$RII4+H+Hv+H+H+HIII$$R226222& 	9*D*288888D9 	3;EC
OOOM''"/,0 (   	  	
rr   c                H    |j          | j        |fi |S  | j        |fi |S r  )_fetch_clausefetch_clauselimit_clause)r  r{  r  s      r   rz  zSQLCompiler._row_limit_clause  sA    '$4$R226222$4$R226222r   c                P    d|j         d||rd|z   nd}t          | |d           S )Nvisit_r  r  )r   r^  )r  r#  
qualifier1
qualifier2attrnames        r   r"  z"SQLCompiler._get_operator_dispatch  sE     J *2C*2

 tXt,,,r   c                   |||fz  }||d<   ||d<   |j         rg|j        rt          j        d          |                     |j         dd          }|r |||j         fi |S  | j        |t          |j                  fi |S |j        rL|                     |j        dd          }|r |||j        fi |S  | j        |t          |j                 fi |S t          j        d          )Nr  r  zFUnary expression does not support operator and modifier simultaneouslyunaryr?  modifierz,Unary expression has no operator or modifier)r?  r  r8   r  r"   _generate_generic_unary_operatorr   _generate_generic_unary_modifier)r  r  r  r  r  r$  s         r   visit_unaryzSQLCompiler.visit_unary  sk    (5(*&7B"#'9B#$> 	~ &2   .. D  tE5>88R888<t<9U^4 8:   ^ 	.. D  tE5>88R888<t<9U^4 8:   ">  r   c                \   | j         j        rw | j        |j        fi |dz    | j        t	          j        |j        |j        j        j        t          j
        u r|j        j        nt          j
                              fi |z   S  | j        |j        fi |dz    | j        |j        fi |z   S )N / )r  div_is_floordivr  ry   r   Castr   r   _type_affinityr%   Numericr  r   r?  r  s       r   visit_truediv_binaryz SQLCompiler.visit_truediv_binary#  s    <' 	V[//B// $,M  &|0?'/ 0  0 #L-- "*!1!3!3    	( V[//B//$,v|22r223r   c                   | j         j        rG|j        j        j        t
          j        u r* | j        |j        fi |dz    | j        |j        fi |z   S d | j        |j        fi |dz    | j        |j        fi |z   z  S )Nr  z	FLOOR(%s))	r  r  r   r   r  r%   Integerr  ry   r  s       r   visit_floordiv_binaryz!SQLCompiler.visit_floordiv_binary>  s    L(	!0H4DDD V[//B//$,v|22r223 V[//B//$,v|22r223 r   c                z    |j         s| j        j        r | j        |j        fi |S d | j        |j        fi |z  S )Nz%s = 1_is_implicitly_booleanr  r  r  r  r  r  r?  r  s       r   visit_is_true_unary_operatorz(SQLCompiler.visit_is_true_unary_operatorO  s[    *	B|3	B  4<662666ldl7?AAbAAAAr   c                    |j         s| j        j        rd | j        |j        fi |z  S d | j        |j        fi |z  S )NNOT %sz%s = 0r  r  s       r   visit_is_false_unary_operatorz)SQLCompiler.visit_is_false_unary_operatorX  s`    *	B|3	B ldl7?AAbAAAAldl7?AAbAAAAr   c                J    d|                      |t          j                  z  S )Nr  )override_operator)visit_binaryr!   match_opr  s       r   visit_not_match_op_binaryz%SQLCompiler.visit_not_match_op_binarya  s.    $++i&8 , 
 
 
 	
r   c                <    d | j         |t          |         fi |z  S r  )_generate_generic_binaryr  r  s       r   visit_not_in_op_binaryz"SQLCompiler.visit_not_in_op_binaryf  s:     55Ih'
 
+-
 
 
 	
r   c                @   |t           j        u r7t          |          dk    r"dd                    d |D                       z  S dS |t           j        u r7t          |          dk    r"dd                    d |D                       z  S dS |                     |          S )	Nr   z(%s)) OR (1 = 1r   c              3     K   | ]}d V  dS r  Nr   r   r  s     r   r1  z6SQLCompiler.visit_empty_set_op_expr.<locals>.<genexpr>r  "      ::f::::::r   zNULL) OR (1 = 1z(%s)) AND (1 != 1c              3     K   | ]}d V  dS r  r   r  s     r   r1  z6SQLCompiler.visit_empty_set_op_expr.<locals>.<genexpr>y  r  r   zNULL) AND (1 != 1)r!   	not_in_opr  rx   in_opvisit_empty_set_expr)r  r  	expand_opr  s       r   visit_empty_set_op_exprz#SQLCompiler.visit_empty_set_op_exprn  s    	+++5zzA~~(II::E:::::  )()/))5zzA~~*II::E:::::  +*,,U333r   c                :    t          d| j        j        z            )Nz3Dialect '%s' does not support empty set expression.rk  r  element_typesr  s      r   r  z SQLCompiler.visit_empty_set_expr  s$    !Al 
 
 	
r   c                   	
 j                              j                  }|sb|j        r8 j        j        rdnd                     j         j        j                  z   }n                     j         gj                  }nf|j        sI|j        rt          |d         t          j                  ryt          |d         t          t          f          sW|j        rt          d           j        j        rdndd                     fdt#          |          D                       z   }n|r j        }|                    |          }|r|                    d          s
J d            |                    d                              d	          }|d
         |d         c	
d                    	
 fd|D                       }n"d                     fd|D                       }d|fS )NVALUES r  r   z?bind_expression() on TupleType not supported with literal_bindsr   c           	   3     K   | ]C\  }}d d                     fdt          |j        j                  D                       z  V  DdS )r  r   c              3  J   K   | ]\  }}                     ||          V  d S r  r   )r   r  
param_typer  s      r   r1  z[SQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>.<genexpr>  sK        -E: 11%DD     r   N)rx   r  r   r  )r   r  r  r,  r  s      r   r1  zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>  s         %A} II    14)9>+?2 2         r   r7   )unexpected format for expanding parameterr  r   r  c              3  Z   K   | ]%}                     |j                  V  &d S r  r  r   )r   r  r  r  r,  r  s     r   r1  zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>  s]       3 3 	  11%HHH 	3 3 3 3 3 3r   c              3  N   K   | ]}                     |j                  V   d S r  r  )r   r  r,  r  s     r   r1  zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>  sI       3 3 --eY^DD3 3 3 3 3 3r   r   )r   r  r  r  tuple_in_valuesr  r  r  _isnullr  collections_abcr   r   bytes_has_bind_expressionr  rx   r  r"  searchr   r  )r  r,  r  bind_expression_templatetyp_dialect_implreplacement_expressionpost_compile_patternr  r  r  r  s   ``       @@r   2_literal_execute_expanding_parameter_literal_bindsz>SQLCompiler._literal_execute_expanding_parameter_literal_binds  s    %>AA$,OO A	
  . 
!%!=EII200N()*= *&& *.)E)E^$i&9* *&& , 0	$0	6!9o&>??0	 vay3,770	
  4 )$   "\9A		r		      )2&(9(9    &"" ( '+'A$(//0HII ?QWW  ? ?>? ? ? ggajj&&t,,$'FCF!)- 3 3 3 3 3 3 3 "(3 3 3 * *&& *. 3 3 3 3 3!'3 3 3 * *&
 )))r   c                   	 j         r                     |          S  j        }j                            |          	 j        r j        n j         j        j        r	j	        r	 	fdnfd|sRg 	j
        r'                     j        j        j                  }n                     j        gj                  }n	j
        sI	j        rt          |d         t           j                  rt          |d         t$          t&          f          sa	j        rJ fdt+          |d          D             |j        rdndd                    fd	t+          |          D                       z   }n=fd
t+          |d          D             d                    fdD                       }|fS )Nc                F                         j        d| iz            S Nr   )render_bind_castr   )r   bind_templater,  r  r  s    r   _render_bindtemplatezNSQLCompiler._literal_execute_expanding_parameter.<locals>._render_bindtemplate  s/    ,,N$!VTN2  r   c                    d| iz  S r  r   )r   r  s    r   r  zNSQLCompiler._literal_execute_expanding_parameter.<locals>._render_bindtemplate  s    $~55r   r   c                Z    g | ]'\  }}t          |d           D ]\  }}d|d||f(S )r   r  r  )r   r  r  r  r  r   s        r   r  zDSQLCompiler._literal_execute_expanding_parameter.<locals>.<listcomp>   sh       $A} )- ; ;  Au  $ttQQQ*E2   r   r   r  r  r   c              3     K   | ];\  d d                     fdt                    D                       z  V  <dS )r  r   c              3  r   K   | ]1\  }} t                    z  |z            d                    V  2dS )r   N)r  )r   r  r  r  r  r-  r  s      r   r1  zMSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>.<genexpr>  si         %Au -,%a#m*<*<&<q&@A!D      r   N)rx   r  )r   r  r  r  r-  s    @@r   r1  zCSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>  s         %A} II        )2-(@(@	         r   c                (    g | ]\  }}d ||fS )r  r   )r   r  r  r   s      r   r  zDSQLCompiler._literal_execute_expanding_parameter.<locals>.<listcomp>  s=       Au !DD!!$e,  r   c              3  4   K   | ]\  }} |          V  d S r  r   )r   r0  r  r  s      r   r1  zCSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>  sD       / /.8c5$$S))/ / / / / /r   )r   r  r  r   r  r:  r4  r3  _bind_typing_render_castsr  r  r  r  r  r  r  r  r   r   r  	_is_arrayr  r  rx   )
r  r   r,  r  r  r  r  r  r-  r  s
   ```   @@@@r   r  z0SQLCompiler._literal_execute_expanding_parameter  s   $ 	JJ6   ,$>AA'JJ 	. 9MM -M L2	6 1	6
        6 6 6 6 6  ,	I. )-)E)EN()*=* *&& *.)E)E^$i&9* *&& , !	$!	6!9o&>??!	 vay3,77!	
 (1111   (1&!(<(<  I %4<		"		      )2&(9(9    &""    )&! 4 4  I &*YY / / / /<E/ / / & &" 000r   c           	     F   |rt          j        |j                  r|l|d         }|j                            t          j        t          |j        j	        |gz             t          |j
        j	        |gz                                  n[|j                            t          j        t          |j        j	                  t          |j
        j	                                       | j        rCt          |j        t          j                  r$t          |j
        t          j                  rd|d<   |p|j        }|                     |dd           }	|	r
 |	||fi |S 	 t           |         }
 | j        ||
f||d|S # t$          $ r}t'          j        | |          |d }~ww xY w)Nenclosing_lateralTr   r   )from_linterlateral_from_linter)r!   is_comparisonr?  rz  rx  r  productr*   ry   r+   r   r2  r  r   rF   r"  r  r  r  r8   r  )r  r   r  eager_groupingr  r  r  r  r#  r$  r%  r  s               r   r  zSQLCompiler.visit_binary  s      	926?CC 	".$&':$;!#)00%!"K59J8KK  ""L6:K9LL 	 	 	 	 	 !((%!&+";<<!&,"<==     	)6;(>??	) 6<)?@@	)
 %)B !%8	**9hEE 	4	00R000$Y/ 5t4 !,(;	 
     P P P5dIFFCOPs   E; ;
F FF c                (     | j         |j        fi |S r  )r  sql_functionr  s       r   &visit_function_as_comparison_op_binaryz2SQLCompiler.visit_function_as_comparison_op_binaryW  s    t|G077B777r   c                    | j         j        r* | j        |j        fi |dz    | j        |j        fi |z   S  | j        |j        fi |dz    | j        |j        fi |z   S )Nz %% r   )r  r  r  ry   r   r  s       r   visit_mod_binaryzSQLCompiler.visit_mod_binaryZ  s    =) 	V[//B//$,v|22r223 V[//B//$,v|22r223r   c                p    |j         |d<    | j        |d|                     |j                  z   dz   fi |S )Nr  r!  )r  r  r  r%  r  s       r   visit_custom_op_binaryz"SQLCompiler.visit_custom_op_binaryh  sW    '6,t,$,,X->???#E
 
 
 
 	
r   c                V     | j         ||                     |j                  dz   fi |S r  )r  r  r%  r  s       r   visit_custom_op_unary_operatorz*SQLCompiler.visit_custom_op_unary_operatorp  sA    4t4T//0ABBSH
 
LN
 
 	
r   c                V     | j         |d|                     |j                  z   fi |S r  )r  r  r%  r  s       r   visit_custom_op_unary_modifierz*SQLCompiler.visit_custom_op_unary_modifieru  sA    4t4S455h6GHHH
 
LN
 
 	
r   c                    |                     dd          }d|d<   |j        |d<    |j        j        | fd|i||z    |j        j        | fd|i|z   }|r|rd|z  }|S )Nr!  FT
_binary_opr  r  )r  r?  ry   r  r   )r  r   r%  r  r  r!  r  s          r   r  z$SQLCompiler._generate_generic_binaryz  s     #%&&)BE"J"J(,$%!?<*FK* %379   .fl- %379 	 	 # 	!~ 	!D=Dr   c                .    | |j         j        | fi |z   S r  rv  r  r  r%  r  s       r   r  z,SQLCompiler._generate_generic_unary_operator  s%    :%-:4FF2FFFFr   c                .     |j         j        | fi ||z   S r  rv  r  s       r   r  z,SQLCompiler._generate_generic_unary_modifier  s$    /u}/;;;;hFFr   c                B    t          j        dt          j                  S )Nz'%')r  )r   literal_columnr%   
STRINGTYPEr4  s    r   _like_percent_literalz!SQLCompiler._like_percent_literal  s    &uH4GHHHHr   c                0    d |j         j        | fi | dS )Nzlower(r  rv  r  s      r   $visit_ilike_case_insensitive_operandz0SQLCompiler.visit_ilike_case_insensitive_operand  s+    I::4FF2FFIIIIr   c                    |                                 }| j        }|                    |j                                      |          |_         | j        ||fi |S r  _cloner  concatr   visit_like_op_binaryr  r   r?  r  percents        r   visit_contains_op_binaryz$SQLCompiler.visit_contains_op_binary  sW    ,~~fl33::7CC(t(@@R@@@r   c                    |                                 }| j        }|                    |j                                      |          |_         | j        ||fi |S r  r  r  r  r   visit_not_like_op_binaryr  s        r   visit_not_contains_op_binaryz(SQLCompiler.visit_not_contains_op_binary  sW    ,~~fl33::7CC,t,VXDDDDDr   c                   |                                 }| j        }t          |j                  |_        |                    t          |j                                                |          |_         | j        ||fi |S r  r  r  r	  ry   r  r   visit_ilike_op_binaryr  s        r   visit_icontains_op_binaryz%SQLCompiler.visit_icontains_op_binary  sw    ,,V[99~~"6<00
 

&// 	 *t)&(AAbAAAr   c                   |                                 }| j        }t          |j                  |_        |                    t          |j                                                |          |_         | j        ||fi |S r  r  r  r	  ry   r  r   visit_not_ilike_op_binaryr  s        r   visit_not_icontains_op_binaryz)SQLCompiler.visit_not_icontains_op_binary  sw    ,,V[99~~"6<00
 

&// 	 .t-fhEE"EEEr   c                    |                                 }| j        }|                    |j                  |_         | j        ||fi |S r  )r  r  _rconcatr   r  r  s        r   visit_startswith_op_binaryz&SQLCompiler.visit_startswith_op_binary  sK    ,''55(t(@@R@@@r   c                    |                                 }| j        }|                    |j                  |_         | j        ||fi |S r  )r  r  r  r   r   r  s        r   visit_not_startswith_op_binaryz*SQLCompiler.visit_not_startswith_op_binary  sK    ,''55,t,VXDDDDDr   c                    |                                 }| j        }t          |j                  |_        |                    t          |j                            |_         | j        ||fi |S r  )r  r  r	  ry   r  r   r  r  s        r   visit_istartswith_op_binaryz'SQLCompiler.visit_istartswith_op_binary  se    ,,V[99''(>v|(L(LMM)t)&(AAbAAAr   c                    |                                 }| j        }t          |j                  |_        |                    t          |j                            |_         | j        ||fi |S r  )r  r  r	  ry   r  r   r  r  s        r   visit_not_istartswith_op_binaryz+SQLCompiler.visit_not_istartswith_op_binary  se    ,,V[99''(>v|(L(LMM-t-fhEE"EEEr   c                    |                                 }| j        }|                    |j                  |_         | j        ||fi |S r  r  r  s        r   visit_endswith_op_binaryz$SQLCompiler.visit_endswith_op_binary  sI    ,~~fl33(t(@@R@@@r   c                    |                                 }| j        }|                    |j                  |_         | j        ||fi |S r  r  r  s        r   visit_not_endswith_op_binaryz(SQLCompiler.visit_not_endswith_op_binary  sI    ,~~fl33,t,VXDDDDDr   c                    |                                 }| j        }t          |j                  |_        |                    t          |j                            |_         | j        ||fi |S r  r  r  s        r   visit_iendswith_op_binaryz%SQLCompiler.visit_iendswith_op_binary  sc    ,,V[99~~&<V\&J&JKK)t)&(AAbAAAr   c                    |                                 }| j        }t          |j                  |_        |                    t          |j                            |_         | j        ||fi |S r  r  r  s        r   visit_not_iendswith_op_binaryz)SQLCompiler.visit_not_iendswith_op_binary  sc    ,,V[99~~&<V\&J&JKK-t-fhEE"EEEr   c                    |j                             dd           } |j        j        | fi |d |j        j        | fi ||#d|                     |t          j                  z   ndz   S )NrS  z LIKE  ESCAPE r  	modifiersr  ry   r  r   r  r%   r  r  r   r?  r  rS  s        r   r  z SQLCompiler.visit_like_op_binary  s    !%%h55 +FK*46626666+FL+D77B777

 ! 2268;NOOOO
 	
r   c                    |j                             dd           } |j        j        | fi |d |j        j        | fi ||#d|                     |t          j                  z   ndz   S )NrS  z
 NOT LIKE r  r  r  r  s        r   r   z$SQLCompiler.visit_not_like_op_binary  s    !%%h55*FK*46626666+FL+D77B777

 ! 2268;NOOOO
 	
r   c                    |t           j        u rF|                                }t          |j                  |_        t          |j                  |_         | j        ||fi |S r  )r!   ilike_opr  r	  ry   r   r  r  s       r   r  z!SQLCompiler.visit_ilike_op_binary  s^    y)))]]__F0==FK1&,??FL )t(@@R@@@r   c                    |t           j        u rF|                                }t          |j                  |_        t          |j                  |_         | j        ||fi |S r  )r!   not_ilike_opr  r	  ry   r   r   r  s       r   r  z%SQLCompiler.visit_not_ilike_op_binary  s^    y---]]__F0==FK1&,??FL -t,VXDDDDDr   c                ^    |j                             dd          } | j        ||rdndfi |S )Nr   Fz BETWEEN SYMMETRIC z	 BETWEEN r  r  r  r  r   r?  r  r   s        r   visit_between_op_binaryz#SQLCompiler.visit_between_op_binary  sN    $((e<<	,t,YG))K
 
KM
 
 	
r   c                ^    |j                             dd          } | j        ||rdndfi |S )Nr   Fz NOT BETWEEN SYMMETRIC z NOT BETWEEN r&  r'  s        r   visit_not_between_op_binaryz'SQLCompiler.visit_not_between_op_binary  sQ    $((e<<	,t,)2G%%
 
 
 
 	
r   c                D    t          j        d| j        j        z            Nz/%s dialect does not support regular expressionsr8   r  r  r   r  s       r   visit_regexp_match_op_binaryz(SQLCompiler.visit_regexp_match_op_binary%  '    =l 
 
 	
r   c                D    t          j        d| j        j        z            r,  r-  r  s       r    visit_not_regexp_match_op_binaryz,SQLCompiler.visit_not_regexp_match_op_binary+  r/  r   c                D    t          j        d| j        j        z            )Nz;%s dialect does not support regular expression replacementsr-  r  s       r   visit_regexp_replace_op_binaryz*SQLCompiler.visit_regexp_replace_op_binary1  s'    Il 
 
 	
r   c           	        |s|j                             | j                  }|j        r|                    |          }	 | j        |	fd||o|j         ||d|}
|j        r~t          j        d|
          }|s
J d            d|	                    d          d|	                    d          d	|	                    d
          d}
|r | j
        |fd|
d|}d|z  S |
S |s|p|j        p|o| j        }|p|j        }nd}|r | j
        |fddi|}|j        rd|z  }|S |                     |          }|| j        v r| j        |         }||ur|j        s|j        rU|j                            |j                  s6|j                            |j                  st'          j        d|z            |j        |j        k    rt'          j        d|d          |j        s|j        rG|j        r|j        rt'          j        d          t'          j        d|j         d|j         d          |x| j        |j        <   | j        |<   | j        }|r@|\  }}|j        D ]3}|j        |v r(||j                 }||                             |           4|j        rd| _        |r.|rd| _        |r| xj        |hz  c_        n| xj        |hz  c_         | j        |f||j        |j         d|}|j        rd|z  }|S )NT)skip_bind_expressionr  literal_bindsr   render_postcompilez&^(.*)\(__\[POSTCOMPILE_(\S+?)\]\)(.*)$r  z(__[POSTCOMPILE_r7   r  r   z~~REPL~~r  z~~]))r  r  r  Fr  zIBind parameter '%s' conflicts with unique bind parameter of the same namez"Can't reuse bound parameter name 'z' in both 'expanding' (e.g. within an IN expression) and non-expanding contexts.  If this parameter is to receive a list/array value, set 'expanding=True' on it for expressions that aren't IN, otherwise use a different parameter name.a)  Encountered unsupported case when compiling an INSERT or UPDATE statement.  If this is a multi-table UPDATE statement, please provide string-named arguments to the values() method with distinct names; support for multi-table UPDATE statements that target multiple tables for UPDATE is very limitedzbindparam() name 'z' is reserved for automatic usage in the VALUES or SET clause of this insert/update statement.   Please use a name other than column name when using bindparam() with insert() or update() (for example, 'b_z').)post_compile	expandingbindparam_type)r   dialect_implr  r  bind_expressionr  r9  rR  r3  r   r  r   r2  _truncate_bindparamr.  r   r  intersectionrm  r8   r  _is_crudr0  rF  r  
isoutparamhas_out_parametersr;  rC  rD  r  )r  r  r  r6  r5  r   r7  r  implr<  wrappedr  r^  r8  r   existingr  r~  r}  rp  rr  s                        r   visit_bindparamzSQLCompiler.visit_bindparam7  s    $ $	>..t|<<D( ""&"6"6y"A"A&$,#)-*?"/"K	8K4K$3'9    & , A7 A IIIIIII











G % ,;d;%265<  %	   &|+ 	! D,D)Bd.B 
 +Ai.ALL L 	/$/ 159? C " #slJ''	224:z$'Hy((_/(1(8/$.;;!+ /
 %0==!- / *ACGH   '9+>>>** :>@   & )*< ( Y-?  ".&
 
 
 ".5 5 5 #,-5 5 5	 	 	 8A@
9=!DJt$4 /
 	/#JD$+ / /6T>>bfBHOOI... 	+&*D# 	8! 0+/( 8++	{:+++((YK7((#d#
%)$>	
 

 
 
  	3,C
r   c                    t                      r  r  )r  r  
dbapi_typero  s       r   r  zSQLCompiler.render_bind_cast  s    !###r   c                   |t           ur|}nz|j        l|j        e|                    dd           }|r5|t          j        t          j        fvrt          j        d|j	        f            | j
        t          j        fi |S |j        }|j        r| j        } ||||          \  }}	|	S |                     ||j                  S )Nr  zBound parameter '%s' rendering literal NULL in a SQL expression; comparisons to NULL should not use operators outside of 'is' or 'is not')r  )r/   r  r  r  r!   is_is_notr&   warn_limitedr0  r  r%   r  r  r9  r  r  r   )
r  r  r  r  r  r  opleepr-  r/  s
             r   r  z$SQLCompiler.render_literal_bindparam  s      v--(EE&9+=+EVVL$// "Y]I4D$EEE%@ #(	   $t|H$5<<<<<-E 		DJD*.$)A+ + +'I'
 $#,,UINCCCr   c                   |8|j         s1|                     t          j                                                  S |                    | j                  }|rL	  ||          S # t          $ r3}t          j	        dt          j        |           d| d          |d}~ww xY wt          j	        dt          j        |           d|           )a  Render the value of a bind parameter as a quoted literal.

        This is used for statement sections that do not accept bind parameters
        on the target driver/database.

        This should be implemented by subclasses using the quoting services
        of the DBAPI.

        Nz Could not render literal value "z" with datatype z); see parent stack trace for more detail.z:No literal value renderer is available for literal value ")should_evaluate_noner  r   Null	_instance_cached_literal_processorr  r  r8   r  sql_util_repr_single_value)r  r  r  	processores        r   r  z SQLCompiler.render_literal_value   s    =!;= << 7 7 9 9:::33DLAA	 		 y'''   &# 3E::# # # # #   ")/66) )!&) )  s   
A# #
B -.BB c                    || j         v r| j         |         S |j        }t          |t          j                  r|                     d|          }|| j         |<   |S )Nr  )r/  r0  r  r   rE   r  )r  r  r  s      r   r=  zSQLCompiler._truncate_bindparam%  sb    ''?9--M	i!:;; 	K22;	JJI &/	"r   ident_classr   rE   c                   ||f| j         v r| j         ||f         S |                    | j                  }t          |          | j        dz
  k    rd| j                            |d          }|dt          | j        dz
  d                   dz   t          |          dd          z   }|dz   | j        |<   n|}|| j         ||f<   |S )N   r   r   r  r7   )	rr  	apply_maprq  r  ro  rs  r  maxhex)r  rX  r   anonnamecounter	truncnames         r   r  z!SQLCompiler._truncated_identifier2  s     $"666'd(;<<>>$-00x==4,q000.22;BBGS!2Q!6:::;g,,qrr"# 
 5<aKD$[11 I4=k401r   c                    || j         z  S r  rq  r  r   s     r   
_anonymizezSQLCompiler._anonymizeG  s    dm##r   r8  r9  escaped_fromr:  Optional[TypeEngine[Any]]accumulate_bind_namesOptional[Set[str]]visited_bindparamr  c                    ||                     |           ||                    |           |s< j                            |          r" j                             fd|          }	|}|	}|r! j                            ||i           _        |rEd|z  }
|r|
S |8|                     j                  }|j	        r 
                    |||
          }
|
S  j        t          j        u r j        d|iz  }
n j        d|iz  }
|D j        j        r8|                     j                  }|j
        r 
                    |||
          }
|
S )Nc                D    j         |                     d                   S )Nr   )r$  r   )r  r  s    r   r  z.SQLCompiler.bindparam_string.<locals>.<lambda>d  s    d8D r   z__[POSTCOMPILE_%s]r   )addr  r#  r  r  rE  r   r  r  render_literal_castr  r  re  rf  r4  r3  r  )r  r   r8  r9  re  r:  rg  ri  r  new_namer^  	type_impls   `           r   r  zSQLCompiler.bindparam_stringJ  s    !,!%%d+++($$T*** 
	 &--d33 	   266DDDD   $ 	&*&=&C&Ct$' 'D#  	5&-C  
 )*BBL 	 0 P//	3OOCJZ=222/64.@CC#vtn4C &6 ' '>>t|LLI) L++NIsKK
r   c                    |                                 }|                    dd            t          |j        |j                  D ]\  }} |j        | fd|i| d S )Ncte_opts)copyr|  r  r  _independent_ctes_optsr  )r  stmtr  local_kwcteopts         r   r  z&SQLCompiler._dispatch_independent_ctes  s~    7799Z&&&"D$?
 
 	C 	CHC #C"4BB#BBBBB	C 	Cr   rv  rN   rx  ashint	fromhintsOptional[_FromHintsType]visiting_cteOptional[CTE]r  Optional[FromLinter]rq  selectable._CTEOptsc                x                                      }	|	 j        u sJ ||d<   |j        }
t          |
t          j                  r                     d|
          }
d}d}|                                }|j        p|j        }| j	        v r j	        |         \  }}}||
k    sJ ||
f} j
        |         }|j        r]|j        rt          j        d          ||
f}|rt           j                  nd}||
fx}} j
        |= | j
        |<   ||fz    j	        |<   n5|rt           j                  nd}||
f}| j
        v r j
        |         }nd }|||u }||j        u s||u rd}nr||j        u r,|	|= |                                }||u sJ ||u sJ  j	        |= n=|j        |j        |                    |          rd}nt          j        d|
z            |s|sd S |j        D|j        }|j        j        }t          |t          j                  r                     d|          }n|}d }|rE| j
        |<   ||fz    j	        |<   | j        vr  j        |fi | |s||	vr|j        rd _         j                            ||
          }|j        rM|j        }d |                    d          D             }|d	d
                     fd|D                       z  z  }|                    dd          du sJ  j        s |j        j         fd|i|S   j        ||j        fi |} |j        j         fddi|}|d|d|dz  }|j        r|d  j        ||j        fi |z   z  }||	|<   |r|r|
|j         |!                                <   |s|r j                            ||
          S |ri j                            ||          } j        "                    |
          r j        #                    |
          }
| $                    |
          z  }|S  j                            ||
          S d S )Nr{  r  TFz6CTE is stated as 'nest_here' in more than one locationr   z5Multiple, unrelated CTEs found with the same name: %rc                &    g | ]\  }}}}}|
|p|S r   r   )r   r  
proxy_namefallback_label_namer  repeateds         r   r  z)SQLCompiler.visit_cte.<locals>.<listcomp>  sF     " " "&/$'"
 ,9z" " "r   r  r   c              3  Z   K   | ]%}j                             |j                   V  &dS )rb  N)r  format_label_namerq  )r   identr  s     r   r1  z(SQLCompiler.visit_cte.<locals>.<genexpr>,  sW       " " !& !M;; % <  " " " " " "r   subqueryrx  r   z
(r  r!  )%r  rJ  r   r  r   rE   r  _get_reference_ctenestingrL  rK  r8   r  r  r  	_restates_is_clone_ofcompare
_cte_alias	visit_cte	recursiverM  r  format_aliasr  _generate_columns_plus_namesrx   r  r  _generate_prefixes	_prefixes	_suffixesry  r*   _requires_quotesr  get_render_as_alias_suffix)r  rv  rx  rx  ry  r{  r  rq  r  	self_ctescte_name
is_new_cteembedded_in_current_named_cte_reference_cter  	cte_levelr  existing_cte_optscte_level_nameexisting_cteold_level_namenew_level_nameexisting_cte_reference_ctepre_alias_ctecte_pre_alias_namer  
col_source
recur_colsprefixesr   s   `                             r   r  zSQLCompiler.visit_cte  s    ((**	DI%%%%!$~8h 9:: 	E11'8DDH
(-%//11+1!1 T333.2.D/+Iq+ ===='2N2>BL
  $, *1  
 #,X!6/6=C
OOOA	3<h2GG+N;:F'79GK :&~6
 ,39DJI'2N!888#6~F##,8L,H) l,,,|0C0C"

.. l+-9-L-L-N-N*1^CCCC1\AAAA*+EFF $0#0<kk,// =!&JJ*,.67  
  	j 	4>%NM!$!4,h.GHH %)%?%?/& &"  M!% D	&69D#N35CG 6D">2 DI--}77777% ;&#Y*>*>= /*.D'}11#x@@= !$J
" " )EEdKK" " "J  F		 " " " " *4	" " "   D zz*e44====z ? :3;9 %+/5    7t6S]   .4   H ;CK: %)-3 E Dhhh>>D= C"9$"9S]# #.4# #  D "&	# 	A >5=!#--//2 A"? A}11#x@@@! A}11#7IJJ=11(;; =#}228<<H77AAA}11#x@@@tr   c                `    |j         rd |d<   |j        r | j        |fi |S  | j        |fi |S )Nr  )joins_implicitly_is_lateralvisit_lateralvisit_aliasr  s      r   visit_table_valued_aliasz$SQLCompiler.visit_table_valued_alias`  sX    # 	% $B} 	3%4%g44444#4#G22r222r   c                     | j         |fi |S r  )r  r  s      r   visit_table_valued_columnz%SQLCompiler.visit_table_valued_columnh  s     t //B///r   c
           
     T   
 |r!d
vrj         sJ 
d<   |	rd
vr	d
v r|	
d<   |1|j        u r( j        j         f|||||d
}|r
|s|rd|d}|S x}
d<   |s|rBt          j        t
          j                  r                     dj                  }nj        }|r j        	                    |          S |r|	r||	j
                                        <    j        j         fd|d	
}|rd|d}|                      j        	                    |                    z   }j        r5j        r.|d
d                    
 fdj        D                       z  z  }|r"|v r                     ||         |          }|S  j        j         fd|i
S )Nr  r  )rx  rx  iscrudry  lateralenclosing_aliasr  r  r  r  T)rx  r  r  r   c              3     K   | ]N}j                             |j                  j        r d  j        j        j        |j        fi z  ndV  OdS ) %sr  N)r  r  r   _render_derived_w_typesr  r  r  r   )r   r  r  r  r  s     r   r1  z*SQLCompiler.visit_alias.<locals>.<genexpr>  s           !M//999 $)#@	!("M$,"E"M$'H#" #"06#" #"!" !"
 &(!(	     r   r  )r  r  r  r  r   r   rE   r  r  r  ry  r*   r  _supports_derived_columns_render_derivedrx   r  format_from_hint_text)r  r  rx  rx  r  ry  r  r  r  r  r  r   
alias_namer^  s   ``        `   r   r  zSQLCompiler.visit_aliask  s     	<"&00 ((((.3*+
 <)77'6110;,-&?+Be+K+K4EM4	# %	 	 	 	E  *V *w *"'%%)L:??Of%67 	(V 	(%*h&?@@ (!77LL

"Z
 -	=--eZ@@@ +	 B7A!%//"3"344EM4!7 6< E  * *"'%%)$99**5*==  C . 53H vII       $)7     $  Ui//00	% 0&  J 45=3 %)/  r   c                (    d|d<    | j         |fi |S )NTr  r  )r  r  r  s      r   visit_subqueryzSQLCompiler.visit_subquery  s&    :t//B///r   c                .    d|d<   d | j         |fi |z  S )NTr  z
LATERAL %sr  )r  lateral_r  s      r   r  zSQLCompiler.visit_lateral  s,    9.d.x>>2>>>>r   c                     | j         |fddi|d |                                j        | fi |}|j        |d |j        j        | fi |z  z  }|S )Nrx  Tz TABLESAMPLE z REPEATABLE (%s))r  _get_methodr  seed)r  tablesamplerx  r  r  s        r   visit_tablesamplezSQLCompiler.visit_tablesample  s    D[<<<<<<<8K##%%8DDDDD

 '&3 3D??B?? D r   c                                          dj                   d                     fdj        D                       }d| S )Nr6  r   c           	   3     K   | ]=}|D ]8} j         t          j        |d j        i                                fi V  9>dS )r  N)r  r   r   _column_typesr  )r   chunkelemr  r  r  s      r   r1  z-SQLCompiler._render_values.<locals>.<genexpr>  s       	
 	
 	
 	
  DL26!/ *,,  	 	
 	
 	
 	
 	
 	
 	
r   r  )
setdefaultr6  rx   _data)r  r  r  tupless   ``` r   _render_valueszSQLCompiler._render_values  ss    
ow'<=== 	
 	
 	
 	
 	
 	
 !	
 	
 	
 	
 	
 "!!!r   c           
           j         |fi }|j        rd }nBt          |j        t          j                  r                     d|j                  }n|j        }|j        rd}nd}|r|r ||nd|j        |	                                <   |rddd<   |d|d 
                     j                            |                    d	d
                     fd|j        D                       d}n|d|d}|S )Nr  zLATERAL r  z(unnamed VALUES element)Fr  r  r   (r   c              3  4   K   | ]} |j         fi V  d S r  r  r  s     r   r1  z+SQLCompiler.visit_values.<locals>.<genexpr>  sL       " " ! 1A0<<<<" " " " " "r   )r  _unnamedr  r   r   rE   r  r  ry  r*   r  r  r  rx   columns)r  r  rx  r  r  rf  r   r  s   `   `   r   visit_valueszSQLCompiler.visit_values  sg   D..2.. 	 DDh&?@@ 	 --hEEDD<D 	 GGG 	,  ,DD2L !'"3"3"5"56  ,&+?#GGAA33DM4G4G4M4MNNNN		 " " " " "%,_" " "    
 !(+r   c                &    d | j         |fi | dS ru  )r  r  s      r   visit_scalar_valueszSQLCompiler.visit_scalar_values  s)    8&4&w55"558888r   c                    d|z   S )Nr   r   )r  alias_name_texts     r   r  z&SQLCompiler.get_render_as_alias_suffix  s    ''r   r   r   r  r   r	  c                    |sJ ||dk    rd| _         d| _        |j        rt          j        d          | j                            t          ||||                     d S )N*FTzxMost backends don't support SELECTing from a tuple() object.  If this is an ORM query, consider using the Bundle object.)r8  r7  r  r8   r  r  r  r   r  s        r   r  zSQLCompiler._add_to_result_map  s     ?gnn$)D!#'D  	"4  
 	##wgu==	
 	
 	
 	
 	
r   c                .     | j         d||d|i n|fi |S )aL  Render a column with necessary labels inside of a RETURNING clause.

        This method is provided for individual dialects in place of calling
        the _label_select_column method directly, so that the two use cases
        of RETURNING vs. SELECT can be disambiguated going forward.

        .. versionadded:: 1.4.21

        NF_label_select_column)r  rt  r   r  column_clause_argsr  s         r   _label_returning_columnz#SQLCompiler._label_returning_column7  sC     )t($,BB2D
 
 
 
 	
r   c                   j                             | j                  }|j        r|s|r|                              }n}|r| j        }|
r|fd}n|ur|fd}nd}|	s
J d            t          t          j                  r'|urt          |j
        j        f          }n|}n|r&|
J d            t          |||j        f          }n|urd}nt          t          j                  r|oj         oj        du}ngt          t          j                  rd}nJt          t          j                  r
j        p|}n&t          t          j                  s
j        d}nd}|rQ|s|
rJ j        }t          |t          j                  st          j        |          n|}t          |||f          }n|}|                    |	||	            |j        | fi |S )
z.produce labeled columns present in a select().c                &     | || f|           d S r  r   )r   r   r   r  r  s       r   r  z;SQLCompiler._label_select_column.<locals>.add_to_result_mapr  s"    &&wwj%HHHHHr   c                ,     | |f|z   |           d S r  r   )r   r   r   r  r  r   s       r   r  z;SQLCompiler._label_select_column.<locals>.add_to_result_mapz  s2    &&y7':E    r   NzX_label_select_column is only relevant within the columns clause of a SELECT or RETURNING)r  z*proxy_name is required if 'name' is passedTF)r  r  r  )r   r;  r  _has_column_expressioncolumn_expressionr  r  r   rI   r  r   r  r  rG   r  r   
TextClauseUnaryExpressionwraps_column_expressionNamedColumn_non_anon_label_anon_name_labelrE   rx  r  )r  r   r   r  rx  r  r   r  r  r  column_is_repeatedneed_column_expressionsr  rB  col_exprr  result_exprrender_with_labelr  s     `               @r   r  z SQLCompiler._label_select_columnL  s1     {''55& 	#	':	 --f55HHH 	%
 !% 7
 " %6"I I I I I I
 ''%6"      !% % 	
 	
:	
 	
 	
 fhn-- \	'v%%+fkfn5F   ' T	' &&; '&& ( $  KK& v%% %)!!FH$9:: *  1"--1D0 "!
 FH$788 *$)!!FH$<== *$*$B$Lf!!
 vx';<<	* *2$(!!$)!  '* B
  2111*0*A' &+X-F -H-.ABBB - $ ,1j]   '!!"7/' 	" 	
 	
 	

 .{-dII6HIIIr   c                F    |                      ||          }|r|d|z   z  }|S r  )get_from_hint_text)r  ro  r   hintr  hinttexts         r   r  z!SQLCompiler.format_from_hint_text  s2    **5$77 	&sX~%Gr   c                    d S r  r   )r  byfromss     r   get_select_hint_textz SQLCompiler.get_select_hint_text      tr   c                    d S r  r   r  r   r  s      r   r  zSQLCompiler.get_from_hint_text  r  r   c                    d S r  r   r  s      r   get_crud_hint_textzSQLCompiler.get_crud_hint_text  r  r   c                ,    d                     |          S r  r  )r  
hint_textss     r   get_statement_hint_textz#SQLCompiler.get_statement_hint_text  s    xx
###r   r  r  r  r  c                   | j          }|r| j        n| j         d         }|                    ||           }|d         }|d         }	|r-|s+|                    |                    |	          d          }
n|                    ||	          }
|
S )Nr  r  r  r   explicit_correlate_fromsimplicit_correlate_froms)r  r  rs  _get_display_froms
difference)r  select_stmtrx  r  r  r  r  r  r  r  ry  s              r   _display_froms_for_selectz%SQLCompiler._display_froms_for_select	  s     z>-5I))4:b>#::;MM 12^, 	' 	!44)8)C)C * * *,	 5  EE "44)8)5 5  E r   translate_select_structurec	           
         |
J d            d|	d<    j          fi |	}
|
j        |	d<   |
j         j         }|r j        s|
 _        |d up|} j        r0  j        fdi|	}|ur|
}}| j          fi |	}
|
j        |r j        n j        d         }|p+|                    dd          p|                    dd          x|rdsd	|	v r|	d	=                      |
|||          }|		                                
                    ddd
           d}j        r#                               \  }}|r||dz   z  }nd }j        r                     |	           j        r|  j        j        fi |	z  }|  j        fi |	z  }d  fd|
j        D             D             }rU|St'          t)          d |
j        D             d |j        D                                 fd j        D              _                             ||
|||||	          }j        r0 fdj        D             }|r|d                     |          z   z  } j        r5|r|r1|st5           j                  nd }                     |          |z   }j        r|d  j        j        fi |	z   z  } j                            d           |S )NzpSQLAlchemy 1.4 requires use of the translate_select_structure hook for structural translations of SELECT objectsFr  r  rx  r  r  r  r  )r  r  zSELECT r!  c                    g | ]}||S r  r   r  s     r   r  z,SQLCompiler.visit_select.<locals>.<listcomp>  s)     
 
 
* }- , }}r   c                Z    g | ]'\  }}}}}                     
|	|||| 
  
        (S ))r   r  r  r  r  r  )r   r   r  r  r   r  rx  r  r  r  r  r  s         r   r  z,SQLCompiler.visit_select.<locals>.<listcomp>  sm       '# ))'&)(;'/,C *    r   c                    g | ]
\  }}}}}|S r   r   r   r0  r  r  r   r  s         r   r  z,SQLCompiler.visit_select.<locals>.<listcomp>  9     	 	 	&/ $ 	 	 	r   c                    g | ]
\  }}}}}|S r   r   r  s         r   r  z,SQLCompiler.visit_select.<locals>.<listcomp>  r  r   c           
     p    g | ]2\  }}}}t          ||t          fd |D                       |          3S )c              3  D   K   | ]}                     ||          V  d S r  r  )r   ork  s     r   r1  z6SQLCompiler.visit_select.<locals>.<listcomp>.<genexpr>  s1      $F$FQY]]1a%8%8$F$F$F$F$F$Fr   )r   r3  )r   r0  r   r  r  rk  s        r   r  z,SQLCompiler.visit_select.<locals>.<listcomp>  sc     $ $ $ *CsE #u$F$F$F$F#$F$F$FFF $ $ $r   c                :    g | ]\  }}|d j         j        fv |S r  r  r   )r   dialect_namehtr  s      r   r  z,SQLCompiler.visit_select.<locals>.<listcomp>  s<       &\2C):#;;; ;;;r   r  )rs  _ambiguous_table_name_mapr&  r  r  r  r  r  _setup_select_stackrr  rx  _hints_setup_select_hintsr  r  r  r  get_select_precolumnscolumns_plus_namesr  r  r  _compose_select_body_statement_hintsr  rJ  r  r  r  r|  )r  r  rx  insert_intory  r  select_wraps_forr  r  r  r  r  is_embedded_selectnew_select_stmtcompile_state_wraps_forr  ry  r  	hint_textbyfrominner_columnsper_dialectr  r  r  r  rk  s   ```                    @@@@r   visit_selectzSQLCompiler.visit_select-  s	     ''- ('' +0&'::
 
!'
 
 3 	)* $-z> 	/D. 	/!.D+47F;
 * 	6=d= $*.4 O k11*7'#. - B B! !)/! ! ,5-5I))4:b>  >yy7??>yy5u==	
5  	("'
 # 	,':f'D'D*+((vw
 
 $[[]]!!$)EJJ	
 	
 	
  	 $ 8 8 E EIv (	C'F( 	A++K@@@  	+D+[2 6<  D 	**;AA&AAA
 
        & #5'  
 
 
4  "	#3#? 	 	 +=	 	 		 	 5G	 	 	  I2$ $ $ $ .2-A	$ $ $D  ((	
 	
 ' 	H   *5*F  K
  Hd::;GGGG 9 	O0 	OH 	O3;EC
OOOM***GG$ND  	C1$1[2 6<   D 	
rr   r   r!  Tuple[str, _FromHintsType]c                      fd|j                                         D             }                     |          }||fS )Nc           	     v    i | ]5\  \  }}}|d j         j        fv ||d|                    d          iz  6S )r  r   T)rx  r  r   r  )r   r  r  r  r  s       r   r`  z3SQLCompiler._setup_select_hints.<locals>.<dictcomp>  sh     
 
 
 + (3 1222 8u//T/BBCD 322r   )r  ry  r  )r  r   r$  r#  s   `   r   r  zSQLCompiler._setup_select_hints  s[    
 
 
 
 /5m.A.A.C.C
 
 
 --f55	&  r   c           	     .   |d         }|d         }|dk    r||d<   nf|rd|d         }	t          |	j                  }
t          |j                  |
k    r0t          j        dd|
|dz   t          |j                  fz            |r-|s+|                    |                    |          d          }n|                    ||          }t          t          |           }|	                    |          }||||d	}| j
                            |           |S )
Nr  r  r   r   z}All selectables passed to CompoundSelect must have identical numbers of columns; select #%d has %d columns, select #%d has %dr   r   r  )r  r  r$   r  )r  r  r  r8   r  r  r  rp   r+   r   r  r  )r  r   r  r  rx  r  r  r  r  r   numcolsry  new_correlate_fromsall_correlate_fromsr  s                  r   r  zSQLCompiler._setup_select_stack  su      12^,Q &E* 	Z(H(899G=344??&!
 &*F899			    	' 	!44)8)C)C * * *,	 5  EE "44)8)5 5  E
 "-"788177HH 02 *	*
 *
	 	
)$$$r   c	                j    |d                     |          z  } j        t          z  r5t          i t	                                 j        t
          z  }	|r _        nd d}	|s|                                }|r[|dz  }|j        r(|d                      fd|D                       z  }n>|d                      fd|D                       z  }n| 	                                z  }|j
        r  j        |j
        fdi}
|
r|d|
z   z  }|	rJ                                  |j        r|  j        |fi z  }|j        r  j        |j        fi }
|
r|d|
z   z  }|j        r|  j        |fi z  }|j        r|  j        |fi z  }|j        |  j        |fi z  }|S )	Nr   Fz 
FROM c           	     4    g | ]} |j         fd dS )T)rx  ry  r  r  )r   fr$  r  r  r  s     r   r  z4SQLCompiler._compose_select_body.<locals>.<listcomp>_  sZ     	 	 	  -, #'&,(3	 
 % 	 	 	r   c                2    g | ]} |j         fd dS )Trx  r  r  )r   r2  r  r  r  s     r   r  z4SQLCompiler._compose_select_body.<locals>.<listcomp>l  sW         -, #'(3  %	   r   r  z 
WHERE z	 
HAVING )rx   rX  rl  rp  rp   rm  r  rstripr  rh  _where_criteriar  r  _group_by_clausesrw  _having_criteria_order_by_clausesrx  ry  rz  _for_update_argfor_update_clause)r  r  r   r  r%  ry  r$  r  r  warn_lintingtr  s   `     ` `  @r   r  z SQLCompiler._compose_select_body:  s    			-(((<44 	!$R//K<,6L /#. K L  	!;;==D 	(JD} 			 	 	 	 	 	 	 "'	 	 	   		      "'  
 
 
 D%%'''D! 	(11& 4?CI A  (a' 	***# 	;(D(::6:::D" 	)11' +1 A  )q((# 	;(D(::6:::D* 	=*D*6<<V<<<D!-*D*6<<V<<<Dr   c                \     d                      fd|D                       }|r|dz  }|S )Nr!  c              3  b   K   | ])\  }}|d v s|j         j        k     |j        fi V  *dS ))Nr  Nr+  )r   prefixr  r  r  s      r   r1  z1SQLCompiler._generate_prefixes.<locals>.<genexpr>  sb       
 
${**ldl>O.O.O &F%d11b11.O.O.O.O
 
r   r  )r  rt  r  r  r+  s   `  ` r   r  zSQLCompiler._generate_prefixes  sZ     
 
 
 
 
(0
 
 
 
 

  	cMFr   c                0   | j         sdS |r|dk    rt          j                    }t          | j                                                   D ]Y}| j        |                                         \  }}}|j        p|j        }||k    p
|o||dz   k    }	|r|	sI| j         |         ||<   Zn| j         }|sdS t          d |D                       }
| 	                    |
          dz   }|d
                    d |                                D                       z  }|dz  }|ry|dk    rst          |                                          D ]Q}| j        |                                         \  }}}| j         |= | j        ||f= | j        |                                = R|S )z
        include_following_stack
            Also render the nesting CTEs on the next stack. Useful for
            SQL structures like UNION or INSERT that can wrap SELECT
            statements containing nesting CTEs.
        r  r   c                    g | ]	}|j         
S r   )r  )r   rv  s     r   r  z2SQLCompiler._render_cte_clause.<locals>.<listcomp>  s    <<<cm<<<r   r!  , 
c                    g | ]}|S r   r   )r   txts     r   r  z2SQLCompiler._render_cte_clause.<locals>.<listcomp>  s     > > > > > >r   z
 )rJ  r&   r  r  keysrL  r  r  rh   get_cte_preamblerx   r  rK  )r  r  rr  rJ  rv  r  r  rq  r  is_rendered_levelrM  cte_texts               r   r  zSQLCompiler._render_cte_clause  s    y 	2  	]Q..#%%DDINN,,-- + +040F**,,1-	8X +9)9$-$> %+N	]Q=N0N "   $5  IcNS		+ 9D 	2<<t<<<==((883>FKK > > > > >???E 	E]Q..DIIKK(( E E040F**,,1-	8X IcN+Y,AB*3+A+A+C+CDDr   c                    |rdS dS )NzWITH RECURSIVEWITHr   )r  r  s     r   rG  zSQLCompiler.get_cte_preamble  s     	##6r   c                R    |j         rt          j        dd           |j        rdndS )zcCalled when building a ``SELECT`` statement, position is just
        before column list.

        a  DISTINCT ON is currently supported only by the PostgreSQL dialect.  Use of DISTINCT ON for other backends is currently silently ignored, however this usage is deprecated, and will raise CompileError in a future release for all backends that do not support this syntax.z1.4versionr   r  )_distinct_onr&   warn_deprecated	_distinctr  r   r  s      r   r  z!SQLCompiler.get_select_precolumns  sG    
  	 3
     %.6{{B6r   c                f     | j         |j        t          t          j                 fi |}|rd|z   S dS )z5allow dialects to customize how GROUP BY is rendered.z
 GROUP BY r  )r	  r7  r  r!   comma_op)r  r   r  group_bys       r   rw  zSQLCompiler.group_by_clause  sO     140$i	0B&C
 
GI
 
  	(**2r   c                f     | j         |j        t          t          j                 fi |}|rd|z   S dS )z5allow dialects to customize how ORDER BY is rendered.z
 ORDER BY r  )r	  r9  r  r!   rT  )r  r   r  rD  s       r   rx  zSQLCompiler.order_by_clause  sO     140$i	0B&C
 
GI
 
  	(**2r   c                    dS )Nz FOR UPDATEr   rR  s      r   r;  zSQLCompiler.for_update_clause  s    }r   rt  rC   returning_colsSequence[ColumnElement[Any]]r  c                     fd                     dt          j        |                    D             }dd                    |          z   S )Nc           
     F    g | ]\  }}}}} j         	|f||||d S ))r  r  r   r  )r  )
r   r   r  r  r   r  r  r  r  rt  s
         r   r  z0SQLCompiler.returning_clause.<locals>.<listcomp>  st     
 
 
# )D(#	 %8#+%	 	 	 	
 
 
r   T)cols
RETURNING r   )r  r   _select_iterablesrx   r  rt  rX  r  r  r  s   `` `` r   returning_clausezSQLCompiler.returning_clause  s}    
 
 
 
 
 
 
" 2241.AA 3  #
 
 
, dii0000r   c                    d}|j         |d | j        |j         fi |z   z  }|j        %|j         |dz  }|d | j        |j        fi |z   z  }|S )Nr  z
 LIMIT z

 LIMIT -1z OFFSET )_limit_clauser  _offset_clause)r  r   r  r  s       r   r  zSQLCompiler.limit_clause(  s}    +K,$,v/C"J"Jr"J"JJJD ,#+%Jf.C!J!Jr!J!JJJDr   c                   ||j         }|j        }nddd}d}|j        I|j        }|r)|                    |          r|                                } | j        |fi |}	|d|	z  z  }n|r|dz  }|X|r)|                    |          r|                                }|d | j        |fi ||d         rdndd	|d
         rdndz  }|S )NF)r  	with_tiesr  z
 OFFSET %s ROWSz
 OFFSET 0 ROWSz
 FETCH FIRST r  z PERCENTz ROWS re  z	WITH TIESONLY)r  _fetch_clause_optionsrc  _simple_int_clauserender_literal_executer  )
r  r   r  require_offset"use_literal_execute_for_simple_intr  fetch_clause_optionsr  offset_clause
offset_strs
             r   r  zSQLCompiler.fetch_clause2  sI    !/L#)#?  /45#I#I  ,"1M2G--m<<G !. D D F F%m::r::J'*44DD 	'&&D#2E--l;;E  ,BBDDD\00R00029=E

2EE3K@LfL D
 r   c	                2   |r|j         |j        |<   |s|r | j                            |          }
|r@|
r>| j                            |
          dz   | j                            |j                  z   }n~| j                            |j                  }|
s]|r[|j        |v rR|                     d||j                           }||                     | j        	                    d |                    z   }|r"||v r| 
                    ||||         |          }|S dS )Nr  r  r  )fullnamery  r  r  r  r  r   r  r  r  r  )r  r   rx  r  rx  ry  
use_schemar  r  r  r  r^  	anon_names                r   visit_tablezSQLCompiler.visit_table[  s`     	6',~Ke$ 	V 	#}>>uEE . M../?@@m))%*556  m))%*55 )0 
&>>> $ : :!9%*!E! !I  ? ?224CC! ! C  Ui//00	% 0&  J2r   c                z   |r[|j                             t          j        t	          |j        j                  t	          |j        j                                       |j        rd}n|j	        rd}nd} |j        j
        | fd|d||z    |j        j
        | fd|d|z   dz    |j        j
        | fd|i|z   S )Nz FULL OUTER JOIN z LEFT OUTER JOIN z JOIN Tr4   ON r  )rz  rx  r  r  r*   ry   r+   r   rv   isouterr  onclause)r  rx   rx  r  r  	join_types         r   
visit_joinzSQLCompiler.visit_join  s-    	$$!di566dj677    9 	!+II\ 	!+II I(DI(!{ >D   ,dj+!{ >D 	  /dm. "-17 	
r   c                      fd|j                                         D             }|j        |v r(                     ||j        ||j                 d          }||fS )Nc                B    i | ]\  \  }}}|d j         j        fv ||S r  r  )r   r   r  r#  r  s       r   r`  z1SQLCompiler._setup_crud_hints.<locals>.<dictcomp>  sC     
 
 
+ )3 1222 9222r   T)r  ry  r   r  )r  rt  
table_textdialect_hintss   `   r   _setup_crud_hintszSQLCompiler._setup_crud_hints  s|    
 
 
 
/3{/@/@/B/B
 
 

 :&&33DJdj(A4 J j((r   r   rK   rC  c                D   | j         j        }|j        }|j        }|dS |j        r!| j                            |j        d          }n | j                            |j        d          }||z  r|S |j	        r+t          j        d|d          d| j         j         d          dS )a)  given a :class:`.Table`, return a usable sentinel column or
        columns for this dialect if any.

        Return None if no sentinel columns could be identified, or raise an
        error if a column was marked as a sentinel explicitly but isn't
        compatible with this dialect.

        Nr   zColumn z@ can't be explicitly marked as a sentinel column when using the a   dialect, as the particular type of default generation on this column is not currently compatible with this dialect's specific INSERT..RETURNING syntax which can receive the server-generated value in a deterministic way.  To remove this error, remove insert_sentinel=True from primary key autoincrement columns; these columns are automatically used as sentinels for supported dialects in any case.)r  "insertmanyvalues_implicit_sentinel _sentinel_column_characteristicsr  
is_autoinc_sentinel_col_autoinc_lookupr  default_characterization _sentinel_col_non_autoinc_lookupis_explicitr8   r2  r   )r  r   sentinel_optssentinel_characteristics	sent_colsbitmasks         r   _get_sentinel_column_for_tablez*SQLCompiler._get_sentinel_column_for_table  s     G#(#I ,4	4#. 	7;;(A1 GG ;??(A1 G 7" 	#/ 	 )
@)A, 
@ 
@<$
@ 
@ 
@   tr   rX   compiled_parameters%List[_MutableCoreSingleExecuteParams]generic_setinputsizesrM  
batch_sizer?  rA  r  r   Iterator[_InsertManyValuesBatch]c              #     123456789:K    j         }|J |j        sd 1nt          j        |j         1t	                    }	|j        r j        j        sd}
d}n, j        j        r|r j	        r|j
        |j        rd}
d}nd}
d}|
r`t          t          dt          |                    d          D ]1\  }\  9}t          |99g1r 1|          gng d||	||
  
        V  2d S |r!t!          j         j        j        |          :nd :|j        }:r :|          }d| d}|                    |d          } j        j        }|rCt	           j                  }t	          |j                  }||z
  }t3          |||z
  |z            }t          d	t5                              }t          d	t5          |                    }d }d}|	|z  |	|z  rdnd
z   }|j        }|J :r:fd|D             }d
x67 j        s j        r j        4ni 4t;          d
                   }4 fd3|j        rd}nd}dd                    3fd|D                        | d}|                     4fd|D                       }fd|!                    |          D             }d5nd}t;                      }i }|j        rd| d5nd| d5t;                      2|j        D ]}2"                    |d                    2r_ j#        }|J 2fdt          |          D             } t3          |           6tI          |           dz   7t	          |           76z
  k    sJ  j%        r2tM          j'         j(                  }!tM          j)        |! dd5          5|r|d
|         }"|d
|         }#g |d
|<   g |d
|<   |r|}$nt	          |"          }$r%d fdtU          |$          D             D             } j        r8|j+        }%|%t	          |"d
                   k    rdx}&}'|"}(n/|"d
         d 6         }&|"d
         7d          }'67fd|"D             }(|j        r7d                    5fdt          |"          D                       d d         })n5|$z  d d         }) j%        rE|%d
k    r?|'rJ 6dz   }*|%|$z  |*z   }+tY           fdtU          |*|+          D                       },|)|,z  })|                    d|)          }-tY          tZ          j.        /                    |(                    }.|&|.z   |'z   }.ng }/|0                                }.t          |"          D ]\  89|                    d tc          8                    }0|j        r#|0                    d!tc          8                    }0|/2                    |0           |."                    89fd"|D                        |                    dd                    |/                    }-t          |-|.||"1r1fd#|#D             ng |$|||d
  
        V  |dz  }|d S d S )$NTFzKSequence[Tuple[_DBAPISingleExecuteParams, _MutableCoreSingleExecuteParams]]r   r  r  r  __EXECMANY_TOKEN__zList[Sequence[Any]]r   c                8    g | ]\  }}}}|| |          |fS r   r   )r   r  r0  r  strsts        r   r  zASQLCompiler._deliver_insertmanyvalues_batches.<locals>.<listcomp>  sB     " " "&CdB c33t99b)" " "r   c                    | D ]E}                     ||          }|                    j        d|iz  j        d| diz            }F|S )Nr   __EXECMANY_INDEX__)r  r  r3  )rF  	formattedr0  rE  r  s      r   apply_placeholderszISQLCompiler._deliver_insertmanyvalues_batches.<locals>.apply_placeholders  sq      C,00c::C ) 1 1)VSM9)!c#=#=#=>?! !II
 ! r   z, _IMV_VALUES_COUNTERr  r   c              3  :   K   | ]\  }}}} ||          V  d S r  r   )r   r  r  	bind_keysr  s       r   r1  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  sL       6 6.Aq)Y #"9i886 6 6 6 6 6r   c              3  X   K   | ]$\  }}}}|D ]}                     ||          V  %d S r  r  )r   r  r  r0  rE  s       r   r1  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  sf       4 4&Aq!Y$4 4  #&&sC004 4 4 4 4 4 4r   c                .    i | ]}|d          |         S )r   r   )r   r0  r'  s     r   r`  zASQLCompiler._deliver_insertmanyvalues_batches.<locals>.<dictcomp>  s4        Z]3'  r   z, _IMV_VALUES_COUNTER), z), r  c                "    h | ]\  }}|v 	|S r   r   )r   r[  r   all_names_we_will_expands      r   r   z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<setcomp>  s3     ( ( (!T777 777r   z\d+r  c                     g | ]\  }}}|||fS r   r   )r   new_keylen_r  s       r   r  zASQLCompiler._deliver_insertmanyvalues_batches.<locals>.<listcomp>  s5     + + +*s dC(+ + +r   c              3  >   K   | ]}D ]\  }}}| d | ||fV  dS )r  Nr   )r   rx  r0  r  r  r  s        r   r1  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  si       / /!.C/ / +Cs  ))%))45/ / / / / / /r   r   c              3  ,   K   | ]}|         V  d S r  r   )r   r_  expand_pos_lower_indexexpand_pos_upper_indexs     r   r1  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  sC       & & 01GGH& & & & & &r   c              3  d   K   | ]*\  }}                     d t          |                    V  +dS )_IMV_VALUES_COUNTERN)r  r   )r   r  r  executemany_values_w_commas      r   r1  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  sX           !%1 7>> 5s1vv            r   c              3  .   K   | ]}j          | V  d S r  r  r   r  r  s     r   r1  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>3  sE       & &  >CCC& & & & & &r   EXECMANY_INDEX__r  c                ,    i | ]}| d  |         S )__r   )r   r0  r  params     r   r`  zASQLCompiler._deliver_insertmanyvalues_batches.<locals>.<dictcomp>T  s)    NNNsC1c
NNNr   c                &    g | ]} |          S r   r   )r   rr  _sentinel_from_paramss     r   r  zASQLCompiler._deliver_insertmanyvalues_batches.<locals>.<listcomp>b  s%    HHH2**2..HHHr   )3rA  rF  r?  r]  r  r;  r  supports_default_metavaluesupports_multivalues_insertr  rD  rB  r  r   r  rJ  	functoolspartialr  r  r<  r  insertmanyvalues_max_parametersr/  r>  minr  rc  rE  rp   rH  rx   r>  r  rx  r+  r\  r:  rR  rS  r5  r  ranger@  r3  r  r  from_iterablerr  r   r  );r  r&  r'  r  r  r  rA  r  imv	lenparamsuse_row_at_a_time
downgradedrR  compiled_paramimv_single_values_exprexecutemany_values
max_paramstotal_num_of_paramsnum_params_per_batchnum_params_outside_of_batchbatchescompiled_batchesrN  rS  r>  all_keysimv_values_counterformatted_values_clausekeys_to_replacebase_parametersr  r+  all_expand_positionsescapedrO  compiled_batchrQ  num_ins_paramsextra_params_leftextra_params_rightbatch_iteratorexpanded_values_stringr  rj   r  rK  rL  replaced_values_clausesfmvr  r  r  rE  r  r  r  r  r  r  s;   ` ` `                                            @@@@@@@@@@r   !_deliver_insertmanyvalues_batchesz-SQLCompiler._deliver_insertmanyvalues_batches  s
      $& 	$(!!$,$7(%! 
OO	 	t|'N 	 !%JJ9 	#	$	 %-1N-
 !%JJ %J 	5>a
$788  6 6  115. -)G 1 ..~>>??+       F 	#7%9  CC
 C!$!7 	A%(S)?%@%@":!7:::%%&8:NOO	 \A
 	"%do"6"6#&s'=#>#> #&:: ( "==+, J ,d:.>.>??!4(;#<#<
 
 HL!Z/Z'.AAQ
 !3!--- 	" " " "*<" " " ;<;!7 M	& (%)%<""%'":a=))H! ! ! ! ! ! ' (%<""%'"''DII 6 6 6 62D6 6 6 - - '' "'' '' ''#
 '33 4 4 4 4*<4 4 4  O
   #..??  O *,&&&(#!eeO O' MH.HHH +* .M1G-L-L-L*14$. 9 9(//Q8888 ( "."...( ( ( (%.{%;%;( ( ($
 *--A)B)B&),-A)B)BQ)F&,---0FFG G G G " )D$GHH-/V$$$d,F. .*  D	AjL)E-a
l;N$&GAjL!-/Qz\* 0%/""%(ZZ"$ + +/ / / /%*+=%>%>/ / /+ + +'  X!$!B "Sq]]22=??%(:%*NN(-a1H2H1H(I%).q2H2I2I)J&& & & & &!&& & &N
 +          )2%(8(8	        rc.** 46HHrc.* & P>A+=+=  21112Q6E(,>?%GC !& & & & &!&uc!2!2& & & ! !I .Di-O*%.%6%6(*@& &" ',O11.AA' '#
 &)*() $# +-'&5&:&:&<&<# )% 0 0 
 
HAu199*CFF C / I!kk*?QHH+223777'..NNNNNoNNN    &/%6%6(II566& &"
 )"#' -HHHHHHHH"'      MHI  D	 D	 D	 D	 D	r   c                x     |j         | fi |}|j        }|||d<   d}n j         }|r#d _         j        s| _         j        s| _         j                            t                      t                      |d           d}d } j        r|g }t          j
         |||fd|i|} j        r7|5t          |          } j        r j         xj        |z  c_        n| _        |j        }	|	sE j        j        s9 j        j        s- j        j        s!t'          j        d j        j        z            |j        r^ j        j        s!t'          j        d j        j        z             j        s|j        r|j        rt'          j        d	          |j        }	n|j        }	 j        }
 j        j        }d
}|j        r|  j        ||j        fi |z  }|dz  }|
                    |j                  }|j         r !                    ||          \  }}|j"        r #                    ||           ||z  }|	s|s%|dd$                    d |	D                       z  z  }|j%        }d }d }d} j        p|j        }|r|j&        }||sJ d |	D             }g }|D ]B}||vrd } n9 '                    |          }|||         vrd } n|                    |           C|3 j        j(        tR          j*        z  rd}n|d         j+        r
J d            tY          |          tY          |          z   } -                    |||          } j.        r|d|z   z  }nd }|j/        w  j0         j        d         d         fddi|} j1        rE j        j2        r9|st           j                  nd }|d 3                    |d          |z  }n|d|z  z  }n|	s]|r[|dz  }|rRti          d j        j5        tm          d|	          ||j        |j7        d u||rt          |          nd|	  	         _8        nn|j        r,|dd$                    d |j9        D                       z  }n;d$                    d tm          d|	          D                       }|r|r j        j(        tR          j:        z  r|j;        sd} j        j(        tR          j<        z  }d$                    d t{          |	          D                       }|r/d$                     fdt{          |	          D                       }n|}|d | d!| d"| d#z  }nd}|d$| d%z  }ti          d|tm          d|	          ||j        |j7        d u||rt          |          nd|||&           _8        n	|d$| d%z  }|j7          j0        |j7        fi |}|r|d|z   z  }|r j.        s|d|z   z  } j1        r> j        j2        s2|st           j                  nd } 3                    |d          |z   } j        >                    d           |S )'Nr{  FTr  r   ri  zWThe '%s' dialect with current database version settings does not support empty inserts.zcThe '%s' dialect with current database version settings does not support in-place multirow inserts.zcRETURNING cannot be determinstically sorted when using an INSERT which includes multi-row values().zINSERT zINTO  (%s)r   c                    g | ]	\  }}}}|
S r   r   )r   r  r  s      r   r  z,SQLCompiler.visit_insert.<locals>.<listcomp>  s     >>>-!T1a>>>r   c                    i | ]
\  }}}}||S r   r   )r   r  r  param_namess       r   r`  z,SQLCompiler.visit_insert.<locals>.<dictcomp>  s2     " " ".Q; " " "r   zTsentinel selection rules should have prevented us from getting here for this dialectr  r!  r  r"  r  rq  r  z DEFAULT VALUESr=  )rA  rB  rD  rE  rG  z VALUES c              3  Z   K   | ]&}d d                     d |D                       z  V  'dS )r  r   c              3  $   K   | ]\  }}}}|V  d S r  r   r   r  r  s      r   r1  z5SQLCompiler.visit_insert.<locals>.<genexpr>.<genexpr>f  s*       L L>1a L L L L L Lr   Nr  )r   crud_param_sets     r   r1  z+SQLCompiler.visit_insert.<locals>.<genexpr>d  s\         ' yy L L^ L L LLLN     r   c                    g | ]	\  }}}}|
S r   r   r  s      r   r  z,SQLCompiler.visit_insert.<locals>.<listcomp>l  s0       &1eQ   r   c              3  &   K   | ]\  }}d | V  dS pNr   )r   r  r  s      r   r1  z+SQLCompiler.visit_insert.<locals>.<genexpr>  s=       ) )$(AqA) ) ) ) ) )r   c              3     K   | ]E\  }^}}                     |j        |j                            j                  d |           V  FdS r  )r  r   r  r  )r   r  r  r  r  s       r   r1  z+SQLCompiler.visit_insert.<locals>.<genexpr>  st       4 4 !-9C! !11 # # @ @ N N 'A 4 4 4 4 4 4r   z SELECT z FROM (VALUES (z)) AS imp_sen(z#, sen_counter) ORDER BY sen_counterz	 VALUES (r  )r;  r<  r>  r@  rA  rB  rD  rE  rF  rG  rH  )?rs  r&  r  r&  r  r  r  rp   rc  r   _get_crud_paramsr  r:  rG  single_paramsr  supports_default_valuesr  supports_empty_insertr8   r  r   _has_multi_parametersr  r,  
_returning_sort_by_parameter_orderr  r  r  format_tabler   r  r~  r  r  rx   use_insertmanyvaluesuse_sentinel_columnsr<  r  rW  r`  _insert_sentinelr  r`  r0  r   r  rJ  cte_follows_insertr  r:  default_metavalue_tokenr   _post_values_clauserA  all_multi_paramsrb  is_default_metavalue_onlyrc  r  r|  ) r  insert_stmtri  r{  r  r  r  counted_bindparamcrud_params_structcrud_params_singler  r  r  r|  r  r  named_sentinel_paramsadd_sentinel_colsrG  rX  _params_by_col_add_sentinel_col
param_namer`  select_textr  r  embed_sentinel_valuerender_bind_castscolnamescolnames_w_castpost_values_clauses    `                               r   visit_insertzSQLCompiler.visit_insertn  s	    ;:
 
!#
 
 $-#!-B~HH:~H 	3 DM) 7)6&% 3%2"
#&55 #) 	
 	
 	
  ! ? 	#|3
 !#!2	
 

 0
 
 
 ? 	?0< #$5 6 6" ?)5**.??***->D*/= #
	L8
	 L;
	 L6	
	 "!\./   . 	B<; &137<3DE   '+6+A6 &I   "4!A!3!A="&,"F  	+D+[2 68  D 	**;+<==
 	L 22;
KKMAz( 	=++K<<<
 	%< 	Gdii>>+=>>>   D  2F9= !0JK4J H	$ 2 G ,++++" "2D" " " )+%): 
= 
=%(>>04-!%!C!C)" "J "8I)JJJ04-)00<<<<(0 G6HI -1)) $5Q#7#H  D   "&n!5!5=N8O8O!O#44$,  5     - /...  $)&$,
234 BFJL K y 
,T\< 
,7? IDJT++&304 ,     K  ++# z	A(? z	A%%D# ):L89;M  &#< $7tC%62CJ-...&7#* * *&& 0 d	AD		   +=*M      DD )-		 *.9*+ +  ) )% $ QA%6E G6MN6E 0I6E ,0( G6NO &
  $yy ) ),56H,I,I) ) )    H ) 3 +/)) 4 4 4 4 1::L0M0M4 4 4 + + +3/? / /$=/ /&./ / /DD ,1(D(ADDDDD):$)'@'+9*( ( 3D#< $7tC%62CJ-...(=&7)=)* * *&&0 @$=@@@@*6!-/" "35" " " 1000 	+D$B 	+C***D9 	T\< 	3;EC
OOOM''"/,0 (   	  	
rr   c                    dS )z3Provide a hook for MySQL to add LIMIT to the UPDATENr   )r  update_stmts     r   update_limit_clausezSQLCompiler.update_limit_clause  s    tr   c                ,    d|d<    |j         | fddi|S )z|Provide a hook to override the initial table clause
        in an UPDATE statement.

        MySQL overrides this.

        Trx  r  r  )r  r	  
from_tableextra_fromsr  s        r   update_tables_clausez SQLCompiler.update_tables_clause  s-     8,z,TEE$E"EEEr   c                     t          d          )z~Provide a hook to override the generation of an
        UPDATE..FROM clause.

        MySQL and MSSQL override this.

        zCThis backend does not support multiple-table criteria within UPDATEr  r  r	  r  r  
from_hintsr  s         r   update_from_clausezSQLCompiler.update_from_clause  s     "%
 
 	
r   c                    |j         || fi |}|j        }|||d<   d}n| j         }|r#d| _        | j        s|| _        | j        s|| _        | j        t          z  r5t          i t                                }| j        t          z  }|r|| _        nd }d}|j        }t          |          }	|	rEt          t          |j                            fd|D             }
                    |          }n
g }
|j        h}| j                            |||d           d}|j        r| | j        ||j        fi |z  } | j        ||j        |
fd|i|}t+          j        | |||fi |}|j        }|j        r|                     ||          \  }}nd }|j        r|                     ||           ||z  }|dz  }|d	                    d
 t;          d|          D                       z  }| j        s|j        r1| j         r*|d| !                    || j        p|j        |          z   z  }|r" | j"        ||j        |
|fd|i|}|r|d|z   z  }|j#        r | j$        |j#        fd|i|}|r|d|z   z  }| %                    |          }|r|d|z   z  }| j        s|j        r1| j         s*|d| !                    || j        p|j        |          z   z  }| j&        r1|stO          | j                  nd }| (                    |          |z   }|r|J |)                    d           | j        *                    d           |S )Nr{  FTc                    g | ]}|v|	S r   r   )r   r2  
main_fromss     r   r  z,SQLCompiler.visit_update.<locals>.<listcomp>  s*     " " "!:*=*=*=*=*=r   r  zUPDATE r  z SET r   c              3  0   K   | ]\  }}}}|d z   |z   V  dS )=Nr   )r   r  r  r  s       r   r1  z+SQLCompiler.visit_update.<locals>.<genexpr>N  sG       
 
!4 3J
 
 
 
 
 
r   zList[Tuple[Any, str, str, Any]]r!  r   WHERE r  UPDATEr  r  )+rs  r&  r  r'  r  r  rX  rl  rp  rp   rm  r  _extra_fromsr  r+   r   r   r  r  r  r  r   r  r  r  r~  r  r  rx   r   r,  r  r0  r`  r  r6  r  r
  rJ  r  r  r  r|  )r  r	  r{  r  r  r  r  r<  r  is_multitablerender_extra_fromsr  r  r|  r  crud_paramsr}  extra_from_textr=  r  r  r  s                        @r   visit_updatezSQLCompiler.visit_update  s    ::
 
!#
 
 $-#!-B~HH:~H 	3 DM) 7)6&% 3%2"<44 	!$R//K<,6L /#. K L#0[)) 		2];+<==>>J" " " "&" " " )..{;;OO!#*01O
#2 /) 	
 	
 	
   	+D+[2 68  D /T.
 
 $	

 
 

 "2+}h
 
:<
 
 )6 	!(,(>(>Z) )%M:: !M( 	=++K<<<
		 
 
%)1;& &
 
 
 
 
 	
 " 	k&< 	- d33+E{/E(0 4      
	.5d5!"	 
 (  O  .o--& 	&11+ 9DHJ A  &	A%//<< 	'C,&&D #	'2'=	0	 C$//'A;+A$, 0    D 9 	O3;EC
OOOM***GG$ND 	1***x000
rr   c                     t          d          )zProvide a hook to override the generation of an
        DELETE..FROM clause.

        This can be used to implement DELETE..USING for example.

        MySQL and MSSQL override this.

        zCThis backend does not support multiple-table criteria within DELETEr  r  s         r   delete_extra_from_clausez$SQLCompiler.delete_extra_from_clause  s     "%
 
 	
r   c                $     |j         | fddd|S )NT)rx  r  r  )r  delete_stmtr  r  r  s        r   delete_table_clausezSQLCompiler.delete_table_clause  s3    ,z,
d
 
.0
 
 	
r   c                    |j         || fi |}|j        }|||d<   d}n| j         }|r#d| _        | j        s|| _        | j        s|| _        | j        t          z  r5t          i t                                }| j        t          z  }|r|| _        nd }d}|j        }|j        h                    |          }	| j                            |	|	|d           d}
|j        r|
 | j        ||j        fi |z  }
|
dz  }
	 |                     ||j        ||          }nJ# t&          $ r= |                     ||j        |          }|r|                     |j        |          }Y nw xY wt+          j        | |||fi | |j        r|                     ||          \  }}nd }|j        r|                     ||           |
|z  }
| j        s|j        r1| j        r*|
d|                     || j        p|j        |	          z   z  }
|r" | j        ||j        ||fd
|i|}|r|
d|z   z  }
|j         r | j!        |j         fd
|i|}|r|
d|z   z  }
| j        s|j        r1| j        s*|
d|                     || j        p|j        |	          z   z  }
| j"        r1|stG          | j                  nd }| $                    |          |
z   }
|r|J |%                    d           | j        &                    d           |
S )Nr{  FTr  zDELETE FROM )r  r!  r  r  r  r  DELETEr  r  )'rs  r&  r  r%  r  r  rX  rl  rp  rp   rm  r  r  r   r   r  r  r  r%  	TypeErrorr  r   r  r  r~  r  r  r,  r  r0  r`  r"  r6  r  rJ  r  r  r  r|  )r  r$  r{  r  r  r  r  r<  r  r  r  r|  r  r}  r  r=  r  s                    r   visit_deletezSQLCompiler.visit_delete  sy   ::
 
!#
 
 $-#!-B~HH:~H 	3 DM) 7)6&% 3%2"<44 	!$R//K<,6L /#. K L#0&,-33K@@
#2 /) 	
 	
 	
   	+D+[2 68  D 		M11!'	 2  JJ  	M 	M 	M 11[. J  MLL!2LLL	M 	dKOOBOOO 	!(,(>(>Z) )%M:: !M( 	=++K<<<
 #	'2'=	,	 C$//'A;+A$, 0    D  
	.;d;!	 
 (  O  .o--& 	&11+ 9DHJ A  &	A% #	'2'=	0	 C$//'A;+A$, 0    D 9 	O3;EC
OOOM***GG$ND 	1***x000
rs   <D AE"!E"c                <    d| j                             |          z  S )NzSAVEPOINT %sr  format_savepointr  savepoint_stmtr  s      r   visit_savepointzSQLCompiler.visit_savepoint  s     > >~ N NNNr   c                <    d| j                             |          z  S )NzROLLBACK TO SAVEPOINT %sr,  r.  s      r   visit_rollback_to_savepointz'SQLCompiler.visit_rollback_to_savepoint   s&    )DM,J,J-
 -
 
 	
r   c                <    d| j                             |          z  S )NzRELEASE SAVEPOINT %sr,  r.  s      r   visit_release_savepointz#SQLCompiler.visit_release_savepoint%  s&    %(F(F)
 )
 
 	
r   )r  r]   r&  r  r  r  rV  r*  rW  r  rX  rj  rY  rZ  r  r   )r  r=  )r  r+  )r  r  )r  r  )r  r  )NT)r  r  r  r  r  r%  )NNTNTF)r  r  r  r  r  r  r  r  r  r  rh  r  r  r\   F)r'  r\   ri  r  r  r%  )r  r9  )NFFNr   )NTr   N)r   r  r  r  r  r  r  r   r  r  r  r   r  r   r  )NF)rK  rZ  r  r  r  r   r  r   )FNNr   )NFNN)FFFFF)rX  r   r   rE   r  r   )r   r   r  r   )FFNNNN)r   r   r8  r  r9  r  re  r=  r:  rf  rg  rh  ri  r?  r  r   r  r   )rv  rN   rx  r  rx  r  ry  rz  r{  r|  r  r}  rq  r~  r  r   r  r=  )FFFNFFNN)
r   r   r   r   r   r   r  r   r  r	  )NNNTFFT)FFNNNFN)r   r!  r  r(  
rt  rC   rX  rY  r  r  r  r   r  r   )NFF)FFFNTNN)r   rK   r  rC  )r&  r   r'  rX   r  r  r  rM  r  r?  rA  r  r  r  r  r  rr  )r   r   r  r  EXTRACT_MAPrP  r&   r  r"  r  r  COMPOUND_KEYWORDSrt  r%  r&  r'  r)  r*  r,  r-  r0  r1  r2  r6  r7  r8  r9  r:  r;  r<  r>  r@  rA  rB  	frozensetrC  rD  r  rE  rA  postfetch_lastrowidrF  r+  rG  rH  rI  rR  rT  r"  r  patternr  r  r  rP  rk  r  r8  r  ro_memoized_propertyr  r  r  r  memoized_propertyr  memoized_instancemethodr  
contextlibcontextmanagerr  r{  rz  r  r  r  r  r  r  r  r|  preload_moduler6  r<  rX  rf  rh  rs  ry  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r	  r  r  r  r&  r-  r1  r5  r<  rF  rI  rN  rS  rY  rU  ri  rf  rc  r~  rz  r"  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r  r  r  r  r   r  r  r(  r*  r.  r1  r3  rE  r  r/   r  r  r=  r  rd  r  r  r$   _CTEOptsr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rd  r   r  r  r  r'  r  r  r  r  r  rG  r  rw  rx  r;  r`  r  r  rs  ry  r~  r-   
CLIENTSIDErW  ra  SENTINEL_DEFAULTNONEr^  r_  r  r   r]  r  r  r  r  r
  r  r  r   r"  r%  r*  r0  r2  r4  r   r   r   r  r  	  s          K 		 		
 	
     : /...6666F)HHH
 +***% .0O//// .0O////$ BFEEEE K((((I----6 %$$$4 ',++++ 5:+9999
 "O!!!! B!!!! ('''
 .---
 &+**** "O!!!! "!!!! ).---- !N     !&%%%% =A @@@@ +/....
 6:9999599999=AAAAA<EIKKGGGG
 :CDDDD
 8<FFFF
   % 	      (,K++++ .21111.22222F,,,, 3222 GFFF&BJ'LMM"
#455$"*$FF'<'DFF  # # [# C C [C )-/3 %%59P P P P Pd = = = X=$ 
   0 ( ( X(  M  M X MD G G XG 
    
!   "!.   .9 9 9vG G GR 

 
 
 
8# # #   X
 6:!
 
 
 
 
2 6:GK!'+ %~ ~ ~ ~ ~@ 
!$ $ "!$L 
3 
3 X
3  %C C C C CJ T344
 
 54
 4333	    
T344P P 54 Pd 
T344, , 54 ,\  > > >@O O O OO O O .3-
 -
 -
 -
` .3+ + + +` !#"/ / / /b
 
 

/ / / ;?".0EI9O 9O 9O 9O 9OvA A A    
 
 
  
  

 
 
 
4 052 2 2 2h      
 
 
  "@ @ @L L L  &  &K K K
 
 
(
 (
 (
T
 
 
:
 
 

 
 

 
 
7 7 7 ;?, , , , ,\8 8 8
 
 
C C C 04? ? ? ?B3 3 3- - - AC$ $ $ $L  6  "B B BB B B
 
 


 
 
4 4 4$
 
 
 ;?H* H* H* H*TM1 M1 M1d  6 6 6 6p8 8 8  
 
 

 
 


 
 
 05   *G G GG G G 
I I IJ J JA A AE E EB B BF F FA A AE E EB B BF F FA A AE E EB B BF F F

 

 

	
 	
 	
A A AE E E
 
 

 
 

 
 

 
 

 
 
 $" c c c cJ$ $ $ $!%	D D D DB# # #J     *$ $ $ $ #&*484815A A A A AFC C C .2&*,0(;
(;E(B(BI I I I IV3 3 30 0 0 b b b bH0 0 0? ? ?   " " "$ $ $ $L9 9 9( ( (
 
 
 
4 EI
 
 
 
8  "  %bJ bJ bJ bJH        $ $ $ .--- 
1t1-		/LM 
  

 ,1   : '+**** K K K KZ
! 
! 
! 
!2 2 2h] ] ]~    %3 3 3 3j  7 7 7 	 	 	
 
 
  1 1 1 1@   +0' ' ' 'X !%. . . .`
 
 
 
<
) 
) 
)" (:t'9,7,>,=,>,1,>,5,5,5,5	
( ($& $D#I#I,1,:	
$ $ < < < <|Y Y Y Yx
 AEp p p pd  F F F
 
 
K K K KZ
 
 
 
 
 

} } } }~O O O
 
 


 
 
 
 
r   r  c                       e Zd ZdZd Z ej        d           fd            Zd Zd Z	d Z
d ZddZd Zd Zd Zd Zd Zd Zd Zd Z xZS )StrSQLCompilera  A :class:`.SQLCompiler` subclass which allows a small selection
    of non-standard SQL features to render into a string value.

    The :class:`.StrSQLCompiler` is invoked whenever a Core expression
    element is directly stringified without calling upon the
    :meth:`_expression.ClauseElement.compile` method.
    It can render a limited set
    of non-standard SQL constructs to assist in basic stringification,
    however for more substantial custom or dialect-specific SQL constructs,
    it will be necessary to make use of
    :meth:`_expression.ClauseElement.compile`
    directly.

    .. seealso::

        :ref:`faq_sql_expression_string`

    c                    dS )Nz<name unknown>r   r  s     r   r  z$StrSQLCompiler._fallback_column_name?  s    r   zsqlalchemy.engine.urlc                h   |j         dk    rt          j        j        } |j                            |j                                                               }|                    |d |           }t          |t                    s |j
        |fi |S t                                          ||          S )Nr   )rY  )stringify_dialectr&   r2  
engine_urlURLr   get_dialectstatement_compilerr  rH  r  r  r  )r  r  r  r  urlr  compilerr  s          r   r  z,StrSQLCompiler.visit_unsupported_compilationB  s    $	11.+CMcgnnW%>??KKMMOOG114 2  H h77 7'x'662666ww44WcBBBr   c                V     | j         |j        fi |d | j         |j        fi |dS )Nr  r   )r  ry   r   r  s       r   visit_getitem_binaryz#StrSQLCompiler.visit_getitem_binaryP  sJ    DL++++++DL,,,,,,
 	
r   c                      | j         ||fi |S r  rS  r  s       r   visit_json_getitem_op_binaryz+StrSQLCompiler.visit_json_getitem_op_binaryV      (t(@@R@@@r   c                      | j         ||fi |S r  rU  r  s       r   !visit_json_path_getitem_op_binaryz0StrSQLCompiler.visit_json_path_getitem_op_binaryY  rW  r   c                >    d| j                             |           dS )Nz<next sequence value: >)r  format_sequencerl  s      r   rf  zStrSQLCompiler.visit_sequence\  s%    OT]%B%B8%L%LOOO	
r   rt  rC   rX  rY  r  r  r  r   r  r   c               t      fdt          j        |          D             }dd                    |          z   S )Nc           	     B    g | ]}                     d |ddi           S )NTFr  r   r  r  s     r   r  z3StrSQLCompiler.returning_clause.<locals>.<listcomp>i  s?     
 
 
 %%dAtUB??
 
 
r   r]  r   )r   r^  rx   r_  s   `     r   r`  zStrSQLCompiler.returning_clausea  sO    
 
 
 
+N;;
 
 
 dii0000r   c                ^     dd<   dd                      fd|D                       z   S )NTrx  r'  r   c              3  8   K   | ]} |j         fd iV  dS ry  Nr  r   r=  r  r  r  s     r   r1  z4StrSQLCompiler.update_from_clause.<locals>.<genexpr>s  sQ       #
 #
 !A BBBrBB#
 #
 #
 #
 #
 #
r   r  r  s   `   ``r   r  z!StrSQLCompiler.update_from_clauseo  s]     8 #
 #
 #
 #
 #
 #
 #
 #
 #
 
 
 
 	
r   c                ^     dd<   dd                      fd|D                       z   S )NTrx  r   c              3  8   K   | ]} |j         fd iV  dS rb  r  rc  s     r   r1  z:StrSQLCompiler.delete_extra_from_clause.<locals>.<genexpr>|  sQ        
  
 !A BBBrBB 
  
  
  
  
  
r   r  r  s   `   ``r   r"  z'StrSQLCompiler.delete_extra_from_clausex  s]     8dii  
  
  
  
  
  
  
  
  
 
 
 
 	
r   c                    dS )NzSELECT 1 WHERE 1!=1r   r  s      r   r  z#StrSQLCompiler.visit_empty_set_expr  s    $$r   c                    d|z  S )Nz[%s]r   r  s      r   r  z!StrSQLCompiler.get_from_hint_text  s    }r   c                      | j         |dfi |S )Nz
 <regexp> r  r  s       r   r.  z+StrSQLCompiler.visit_regexp_match_op_binary  s    ,t,V\HHRHHHr   c                      | j         |dfi |S )Nz <not regexp> ri  r  s       r   r1  z/StrSQLCompiler.visit_not_regexp_match_op_binary  s     ,t,V5ELLLLLr   c                X    d |j         j        | fi |d |j        j        | fi |dS )Nz<regexp replace>(r   r  )ry   r  r   r  s       r   r3  z-StrSQLCompiler.visit_regexp_replace_op_binary  sN     *FK*46626666+FL+D77B7777
 	
r   c                X    d |j         j        | fi |d |j        j        | fi |dS )Nz	TRY_CAST(r   r  )r+  r  r  )r  r   r  s      r   visit_try_castzStrSQLCompiler.visit_try_cast  sN     *DK*4::6::::.DO.t>>v>>>>
 	
r   r7  )r   r   r  r  r  r&   rB  r  rS  rV  rY  rf  r`  r  r"  r  r  r.  r1  r3  rm  r  r  s   @r   rH  rH  +  sE        &      T011C C C C 21C
 
 
A A AA A A
 
 

1 1 1 1
 
 

 
 
% % %  I I IM M M
 
 

 
 
 
 
 
 
r   rH  c                  z   e Zd ZdZer	 	 	 dCdDdZej        d             Zej        d             Z		 	 	 dEdFdZ
d Zd Zd Zd ZdGdZ	 dHdZd  Zd! Zd" Z	 dId#Zd$ ZdGd%Zd& Zd' Zd( Zd) Zd* Zd+ Zd, Zd- ZdHd.Zd/ Z d0 Z!d1 Z"d2 Z#d3 Z$d4 Z%d5 Z&d6 Z'd7 Z(d8 Z)d9 Z*d: Z+d; Z,d< Z-d= Z.d> Z/d? Z0d@ Z1dA Z2dB Z3dS )JDDLCompilerT.r  r]   r&  rA   r  r  r  r  r  r  c                    d S r  r   r  s         r   r  zDDLCompiler.__init__  s	     3r   c                P    | j                             | j         d | j                  S )Nr  )r  rO  r  r4  s    r   r  zDDLCompiler.sql_compiler  s-    |..L$T5N / 
 
 	
r   c                    | j         j        S r  )r  r  r4  s    r   type_compilerzDDLCompiler.type_compiler  s    |22r   Nr  r  r  r  r  r  r  c                    d S r  r   r  s       r   r  zDDLCompiler.construct_params  s	     tr   c                   |j         }t          |j        t          j                  r|                                }| j        }|                    |j                  }t          |          dk    r|d         d}}n|d         |d         }}|	                    d|           |	                    d|           |	                    d|
                    |j                             | j                            |j        |z            S )Nr   r   r  r  r   r#   rp  )contextr  targetr#   rK   rr  r  format_table_seqr  r  r  r  r  r&  )r  ddlr  rv  r  pathr   schs           r   	visit_ddlzDDLCompiler.visit_ddl  s    +cj&,// 	NllnnG}H,,SZ88D4yyA~~!!Wbs!"XtAwsw...x---z8+@+@+L+LMMM 223=73JKKKr   c                b    d}|j         r|dz  }|| j                            |j                  z   S )NzCREATE SCHEMA IF NOT EXISTS )if_not_existsr  format_schemar  )r  r   r  r  s       r   visit_create_schemazDDLCompiler.visit_create_schema  s:     	%$$Ddm11&.AAAAr   c                ~    d}|j         r|dz  }|| j                            |j                  z  }|j        r|dz  }|S )NzDROP SCHEMA 
IF EXISTS  CASCADE)	if_existsr  r  r  cascader  dropr  r  s       r   visit_drop_schemazDDLCompiler.visit_drop_schema  sP    > 	!L D++DL999< 	JDr   c                   |j         }| j        }d}|j        r |d                    |j                  dz   z  }|dz  }|j        r|dz  }||                    |          dz   z  }|                     |          }|r||dz   z  }|dz  }d}d}|j        D ]}	|	j         }
	 |                     |	|
j	        o|           }|||z  }d	}|d
|z   z  }|
j	        rd}D# t          j        $ r8}t          j        d|j        d|
j        d|j        d                   |d }~ww xY w|                     ||j                  }|r||d
z   |z   z  }|d|                     |          z  z  }|S )Nz
CREATE r!  zTABLE r~  r  
Ffirst_pkrC  	Tz(in table 'z', column 'z'): r   ) _include_foreign_key_constraintsz
)%s

)r  r  r  rx   r  r  create_table_suffixr  r  rS  r8   r  descriptionr   argscreate_table_constraintsinclude_foreign_key_constraintspost_create_table)r  r   r  r   r  r  r  r  r  create_columnr   	processedceconsts                 r   visit_create_tablezDDLCompiler.visit_create_table  s   =? 	4CHHU_--33D 	%$$D%%e,,s22"66u== 	.'#--D	 #^ 	 	M"*F LL!F,>,Ox< )  	 (I%D &ID9,,D% $#H#   &&(((&+++rwqzzC   ---3-S . 
 
  	-I$u,,Dd44U;;;;s   9CD&3DDFc                     |j         }|j        rd S                      ||          }d                     fd|j        D                       }|r|d|z   z  }|S )Nr  r!  c              3  B   K   | ]}                     |          V  d S r  )r  r   r   r  s     r   r1  z2DDLCompiler.visit_create_column.<locals>.<genexpr>  s@       
 
)3DLL$$
 
 
 
 
 
r   )r  systemget_column_specificationrx   constraints)r  r   r  r  r   r  r  s   `      r   visit_create_columnzDDLCompiler.visit_create_column  s    = 	4,,Vh,GG 
 
 
 
7=7I
 
 
 
 
  	 C%KDr   c                L    g }j         r|                    j                    j        }||                    |          nt	                      |                    fdj        D                        d                    d  fd|D             D                       S )Nc                .    g | ]}|j         u|v|S r   )rS  )r   r  	omit_fkcsr   s     r   r  z8DDLCompiler.create_table_constraints.<locals>.<listcomp>/  s;       E---!92D2D 2D2D2Dr   z, 
	c              3     K   | ]}||V  	d S r  r   )r   r  s     r   r1  z7DDLCompiler.create_table_constraints.<locals>.<genexpr>6  s4       
 
 }  }}}
 
r   c              3     K   | ]K}|                               j        j        rt          |d d          4                    |          V  LdS )	use_alterFN)_should_create_for_compilerr  supports_alterr^  r  r  s     r   r1  z7DDLCompiler.create_table_constraints.<locals>.<genexpr>8  s|        ::4@@
 3 #:{EBBZ((     r   )rS  r  foreign_key_constraintsr  rp   r!  _sorted_constraintsrx   )r  r   r  r  r  all_fkcsr  s   ``    @r   r  z$DDLCompiler.create_table_constraints  s    
  	2u01110+7 ++,LMMIII    2  	
 	
 	
 }} 
 
   "-  
 
 
 
 
 	
r   c                b    d}|j         r|dz  }|| j                            |j                  z   S )Nz
DROP TABLE r  )r  r  r  r  r  s       r   visit_drop_tablezDDLCompiler.visit_drop_tableD  s8    > 	!L Ddm00>>>>r   c                F    d| j                             |j                  z   S )Nz
DROP VIEW r  r  r  r  r  r  s      r   visit_drop_viewzDDLCompiler.visit_drop_viewJ  s     : :4< H HHHr   c                L    |j         t          j        d|j        z            d S )Nz,Index '%s' is not associated with any table.)r   r8   r  r   r  rx  s     r   _verify_index_tablezDDLCompiler._verify_index_tableM  s1    ;">K   r   c           	         |j         }                     |            j        }d}|j        r|dz  }|j        t          j        d          |dz  }|j        r|dz  }|                     ||          d|	                    |j
        |          d	d
                     fd|j        D                       dz  }|S )NzCREATE UNIQUE z0CREATE INDEX requires that the index have a namezINDEX r~  include_schemaru  rq  r  r   c              3  R   K   | ]!}j                             |d d          V  "dS )FTr  r6  N)r  r  )r   r  r  s     r   r1  z1DDLCompiler.visit_create_index.<locals>.<genexpr>j  sX          !))T *       r   r  )r  r  r  r   r   r8   r  r  _prepared_index_namer  r   rx   expressions)r  r   r  include_table_schemar  rx  r  r  s   `       r   visit_create_indexzDDLCompiler.visit_create_indexS  s&      '''=< 	ID:"B   	 	%$$D%%eN%KKKK!!(< "     II     "-	      
 	
 r   c                    |j         }|j        t          j        d          d}|j        r|dz  }||                     |d          z   S )Nz.DROP INDEX requires that the index have a namez
DROP INDEX r  Tr  )r  r   r8   r  r  r  )r  r  r  rx  r  s        r   visit_drop_indexzDDLCompiler.visit_drop_indexs  sb    :"@   > 	!L Dd//d/KKKKr   c                    |j          | j                            |j                   }nd }|r|r| j                            |          }nd }| j                            |          }|r|dz   |z   }|S Nr  )r   r  r  r  format_index)r  rx  r  r  schema_name
index_names         r   r  z DDLCompiler._prepared_index_name  s    ;"#}>>u{KK# 	. 	-445EFFKKK]//66
 	8$s*Z7Jr   c                    d| j                             |j        j                  d|                     |j                  S )NALTER TABLE z ADD )r  r  r  r   r  r  r   r  s      r   visit_add_constraintz DDLCompiler.visit_add_constraint  s@     M&&v~';<<<<LL(((
 	
r   c                    d| j                             |j                  d| j                            |j        j        t          j                              S )NzCOMMENT ON TABLE r   )r  r  r  r  r  commentr%   Stringr  s      r   visit_set_table_commentz#DDLCompiler.visit_set_table_comment  sV     M&&v~666622&(9(9  
 	
r   c                F    d| j                             |j                  z  S )NzCOMMENT ON TABLE %s IS NULLr  r  s      r   visit_drop_table_commentz$DDLCompiler.visit_drop_table_comment  s(    ,t}/I/IL0
 0
 
 	
r   c                    d| j                             |j        dd          d| j                            |j        j        t          j                              S )NzCOMMENT ON COLUMN T)	use_tablerq  r   )r  format_columnr  r  r  r  r%   r  r  s      r   visit_set_column_commentz$DDLCompiler.visit_set_column_comment  sj     M''$4 (     22&(9(9  	
 	
r   c                J    d| j                             |j        d          z  S )NzCOMMENT ON COLUMN %s IS NULLT)r  )r  r  r  r  s      r   visit_drop_column_commentz%DDLCompiler.visit_drop_column_comment  s0    -0K0KLD 1L 1
 1
 
 	
r   c                F    t          j        | t          |                    r  r  r  s      r   visit_set_constraint_commentz(DDLCompiler.visit_set_constraint_comment  s    -dDLLAAAr   c                F    t          j        | t          |                    r  r  r  s      r   visit_drop_constraint_commentz)DDLCompiler.visit_drop_constraint_comment  s    -dDJJ???r   c                R   g }|j         |                    d|j         z             |j        |                    d|j        z             |j        |                    d|j        z             |j        |                    d|j        z             |j        |                    d           |j        |                    d           |j        |                    d|j        z             |j        |                    |j        rdnd	           d
	                    |          S )NzINCREMENT BY %dzSTART WITH %dzMINVALUE %dzMAXVALUE %dzNO MINVALUEzNO MAXVALUEzCACHE %dCYCLEzNO CYCLEr!  )
	incrementr  r  minvaluemaxvalue
nominvalue
nomaxvaluecachecyclerx   )r  identity_optionsr  s      r   get_identity_optionsz DDLCompiler.get_identity_options  s*   %1KK),<,FFGGG!-KK*:*@@AAA$0KK(8(AABBB$0KK(8(AABBB&2KK&&&&2KK&&&!-KK
%5%;;<<<!-KK#3#9IzJJJxx~~r   c                    d}|j         r|dz  }|| j                            |j                  z  }|r||z  }|                     |j                  }|r|d|z   z  }|S )NzCREATE SEQUENCE r~  r!  )r  r  r\  r  r  )r  r   r@  r  r  optionss         r   visit_create_sequencez!DDLCompiler.visit_create_sequence  sz    ! 	%$$D--fn=== 	FND++FN;; 	"C'M!Dr   c                b    d}|j         r|dz  }|| j                            |j                  z   S )NzDROP SEQUENCE r  )r  r  r\  r  r  s       r   visit_drop_sequencezDDLCompiler.visit_drop_sequence  s8    > 	!L Ddm33DLAAAAr   c                   |j         }|j        | j                            |          }nd }|t	          j        d|j         z            d| j                            |j         j                  d|j        rdnd||j	        rdndS )Nz<Can't emit DROP CONSTRAINT for constraint %r; it has no namer  z DROP CONSTRAINT r  r  r  )
r  r   r  format_constraintr8   r  r  r   r  r  )r  r  r  r   formatted_names        r   visit_drop_constraintz!DDLCompiler.visit_drop_constraint  s    \
?&!]<<ZHHNN!N!"!#'<0   " M&&t|'9:::: N2LL2N,.JJB.	
 	
r   c                   | j                             |          dz   | j        j                            |j        |          z   }|                     |          }||d|z   z  }|j         |d|                     |j                  z   z  }|j        ,| j        j	        r |d|                     |j                  z   z  }|j
        s|j        r| j        j	        s|dz  }|S )Nr!  )r  z	 DEFAULT z	 NOT NULL)r  r  r  r  r  r   get_column_default_stringcomputedidentitysupports_identity_columnsnullable)r  r   r  colspecr   s        r   r  z$DDLCompiler.get_column_specification  s   M''//l199V :   	 0088{W,,G?&sT\\&/::::G O'6 ( sT\\&/::::G 	#	#'+|'M	# {"Gr   c                    dS Nr  r   r  r   s     r   r  zDDLCompiler.create_table_suffix      rr   c                    dS r  r   r  s     r   r  zDDLCompiler.post_create_table  r  r   c                    t          |j        t          j                  r|                     |j        j                  S d S r  )r  server_defaultr#   DefaultClauserender_default_stringargr  s     r   r  z%DDLCompiler.get_column_default_string  s9    f+V-ABB 	--f.C.GHHH4r   c                    t          |t                    r%| j                            |t          j                  S | j                            |d          S )NT)r6  )r  r   r  r  r%   r  r  )r  r   s     r   r  z!DDLCompiler.render_default_string  sV    gs## 	J$99,   $,,WD,IIIr   c                d    |j         r|                     |          S |                     |          S r  )is_column_levelvisit_column_check_constraintvisit_check_constraintr  r   r  s      r   &visit_table_or_column_check_constraintz2DDLCompiler.visit_table_or_column_check_constraint!  s5    % 	;55jAAA..z:::r   c                    d}|j         $| j                            |          }||d|z  z  }|d| j                            |j        dd          z  z  }||                     |          z  }|S Nr  CONSTRAINT %s z
CHECK (%s)FTr  r   r  r  r  r  ro  define_constraint_deferrabilityr  r   r  r  r  s        r   r  z"DDLCompiler.visit_check_constraint'      ?&!]<<ZHHN)(>99t088e4  9  
  
 
 	
 	44Z@@@r   c                    d}|j         $| j                            |          }||d|z  z  }|d| j                            |j        dd          z  z  }||                     |          z  }|S r	  r  r  s        r   r  z)DDLCompiler.visit_column_check_constraint3  r  r   c                :    t          |          dk    rdS d}|j        $ j                            |          }||d|z  z  }|dz  }|dd                     fd|j        r|j        n|j        D                       z  z  }|                     |          z  }|S )Nr   r  r
  zPRIMARY KEY r  r   c              3  V   K   | ]#}j                             |j                  V  $d S r  r  r  r   r_  s     r   r1  z;DDLCompiler.visit_primary_key_constraint.<locals>.<genexpr>H  sI       #
 #
 M''#
 #
 #
 #
 #
 #
r   )	r  r   r  r  rx   _implicit_generatedcolumns_autoinc_firstr  r  r  s   `    r   visit_primary_key_constraintz(DDLCompiler.visit_primary_key_constraint?  s    z??a2?&!]<<ZHHN)(>99 #
 #
 #
 #
 1(
00'#
 #
 #
 
 
 
 	
 	44Z@@@r   c           
         | j         d}|j        $| j                             |          }||d|z  z  }t          |j                  d         j        j        }|dd                    fd|j        D                       d|                     ||          dd                    fd	|j        D                       d
z  }|| 	                    |          z  }|| 
                    |          z  }||                     |          z  }|S )Nr  r
  r   zFOREIGN KEY(r   c              3  V   K   | ]#}                     |j        j                  V  $d S r  )r  parentr   r   r2  r  s     r   r1  z;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>\  D        23qx}--     r   z) REFERENCES r  c              3  V   K   | ]#}                     |j        j                  V  $d S r  )r  r   r   r  s     r   r1  z;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>b  r  r   r  )r  r   r  r  r   r   r   rx   define_constraint_remote_tabledefine_constraint_matchdefine_constraint_cascadesr  )r  r   r  r  r  remote_tabler  s         @r   visit_foreign_key_constraintz(DDLCompiler.visit_foreign_key_constraintS  sm   =?&!]<<ZHHN)(>99J/003:@II    7A7J       //L(    II    7A7J      

 
	
 	,,Z888//
;;;44Z@@@r   c                ,    |                     |          S )z=Format the remote table clause of a CREATE CONSTRAINT clause.)r  )r  r   r   r  s       r   r  z*DDLCompiler.define_constraint_remote_tablek  s     $$U+++r   c                *    t          |          dk    rdS d}|j        $ j                            |          }||d|z  z  }|d  j        |fi |dd                     fd|D                       dz  }|                     |          z  }|S )	Nr   r  r
  r  r  r   c              3  V   K   | ]#}j                             |j                  V  $d S r  r  r_  s     r   r1  z6DDLCompiler.visit_unique_constraint.<locals>.<genexpr>z  s5      FFadm))!&11FFFFFFr   r  )r  r   r  r  !define_unique_constraint_distinctrx   r  r  s   `    r   visit_unique_constraintz#DDLCompiler.visit_unique_constraintp  s    z??a2?&!]<<ZHHN)(>992D2:DDDDDDIIFFFF:FFFFFFF
 	
 	44Z@@@r   c                    dS r  r   r  s      r   r$  z-DDLCompiler.define_unique_constraint_distinct  r  r   c                    d}|j         +|d| j                            |j         t                    z  z  }|j        +|d| j                            |j        t
                    z  z  }|S )Nr  z ON DELETE %sz ON UPDATE %s)ondeleter  validate_sql_phraseFK_ON_DELETEonupdateFK_ON_UPDATEr  r   r  s      r   r  z&DDLCompiler.define_constraint_cascades  s|    *Odm&G&G#\' '  D *Odm&G&G#\' '  D r   c                    d}|j         |j         r|dz  }n|dz  }|j        +|d| j                            |j        t                    z  z  }|S )Nr  z DEFERRABLEz NOT DEFERRABLEz INITIALLY %s)r   r   r  r)  FK_INITIALLYr-  s      r   r  z+DDLCompiler.define_constraint_deferrability  so     ,$ *%))+Odm&G&G$l' '  D r   c                2    d}|j         |d|j         z  z  }|S )Nr  z	 MATCH %s)r3  r-  s      r   r  z#DDLCompiler.define_constraint_match  s'    'K*"222Dr   c                    d| j                             |j        dd          z  }|j        du r|dz  }n|j        du r|dz  }|S )NzGENERATED ALWAYS AS (%s)FTr  z STOREDz VIRTUAL)r  r  ro  	persisted)r  	generatedr  r  s       r   visit_computed_columnz!DDLCompiler.visit_computed_column  sj    )D,=,E,EU$ -F -
 -
 
 $&&IDD E))JDr   c                b    d|j         rdndd}|                     |          }|r|d|z  z  }|S )Nz
GENERATED ALWAYSz
BY DEFAULTz AS IDENTITYr  )alwaysr  )r  r  r  r  r  s        r   visit_identity_columnz!DDLCompiler.visit_identity_column  sP      9HH\99
 ++H55 	&Gg%%Dr   )...)
r  r]   r&  rA   r  r  r  r  r  r  r  r  r5  r  )FT)4r   r   r  r  r   r  r&   r>  r  rs  r  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r%  r$  r  r  r  r4  r8  r   r   r   ro  ro    sP       F 	 FI,/03	 	 	 	 	 

 
 

 
3 3 3
 6:GK!	    L L L&B B B  2 2 2h     7;#
 #
 #
 #
J? ? ?I I I   BF   @L L L    
 
 

 
 

 
 


 
 

 
 

B B B@ @ @  (   B B B
 
 
&  6      J J J; ; ;
 
 

 
 
  (  0, , ,
    
 
 
          r   ro  c                  *   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd1dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1dS )2GenericTypeCompilerc                    dS )NFLOATr   r  s      r   visit_FLOATzGenericTypeCompiler.visit_FLOAT      wr   c                    dS )NDOUBLEr   r  s      r   visit_DOUBLEz GenericTypeCompiler.visit_DOUBLE      xr   c                    dS )NzDOUBLE PRECISIONr   r  s      r   visit_DOUBLE_PRECISIONz*GenericTypeCompiler.visit_DOUBLE_PRECISION  s    !!r   c                    dS )NREALr   r  s      r   
visit_REALzGenericTypeCompiler.visit_REAL  r  r   c                ^    |j         dS |j        dd|j         iz  S d|j         |j        dz  S )NNUMERICzNUMERIC(%(precision)s)	precisionz!NUMERIC(%(precision)s, %(scale)s)rJ  scalerK  r  s      r   visit_NUMERICz!GenericTypeCompiler.visit_NUMERIC  J    ?"9[ +{EO.LLL6"_: :  r   c                ^    |j         dS |j        dd|j         iz  S d|j         |j        dz  S )NDECIMALzDECIMAL(%(precision)s)rJ  z!DECIMAL(%(precision)s, %(scale)s)rK  rK  r  s      r   visit_DECIMALz!GenericTypeCompiler.visit_DECIMAL  rN  r   c                    dS )NINTEGERr   r  s      r   visit_INTEGERz!GenericTypeCompiler.visit_INTEGER      yr   c                    dS )NSMALLINTr   r  s      r   visit_SMALLINTz"GenericTypeCompiler.visit_SMALLINT      zr   c                    dS )NBIGINTr   r  s      r   visit_BIGINTz GenericTypeCompiler.visit_BIGINT  rB  r   c                    dS )N	TIMESTAMPr   r  s      r   visit_TIMESTAMPz#GenericTypeCompiler.visit_TIMESTAMP  s    {r   c                    dS )NDATETIMEr   r  s      r   visit_DATETIMEz"GenericTypeCompiler.visit_DATETIME  rY  r   c                    dS )NDATEr   r  s      r   
visit_DATEzGenericTypeCompiler.visit_DATE  r  r   c                    dS )NTIMEr   r  s      r   
visit_TIMEzGenericTypeCompiler.visit_TIME  r  r   c                    dS )NCLOBr   r  s      r   
visit_CLOBzGenericTypeCompiler.visit_CLOB  r  r   c                    dS )NNCLOBr   r  s      r   visit_NCLOBzGenericTypeCompiler.visit_NCLOB  r>  r   Nc                p    |}|r	|d|z  z  }n|j         r|d|j         z  z  }|j        r|d|j        z  z  }|S )N(%d)z COLLATE "%s")lengthr  )r  r  r   length_overrider  s        r   _render_string_typez'GenericTypeCompiler._render_string_type  s[     	*F_,,DD\ 	*FU\))D? 	6Oeo55Dr   c                .    |                      |d          S )NCHARrs  r  s      r   
visit_CHARzGenericTypeCompiler.visit_CHAR      ''v666r   c                .    |                      |d          S )NNCHARrv  r  s      r   visit_NCHARzGenericTypeCompiler.visit_NCHAR   s    ''w777r   c                .    |                      |d          S )NVARCHARrv  r  s      r   visit_VARCHARz!GenericTypeCompiler.visit_VARCHAR  s    ''y999r   c                .    |                      |d          S )NNVARCHARrv  r  s      r   visit_NVARCHARz"GenericTypeCompiler.visit_NVARCHAR  s    ''z:::r   c                .    |                      |d          S )NTEXTrv  r  s      r   
visit_TEXTzGenericTypeCompiler.visit_TEXT	  rx  r   c                    dS )NUUIDr   r  s      r   
visit_UUIDzGenericTypeCompiler.visit_UUID  r  r   c                    dS )NBLOBr   r  s      r   
visit_BLOBzGenericTypeCompiler.visit_BLOB  r  r   c                .    d|j         r
d|j         z  pdz   S )NBINARYrp  r  rq  r  s      r   visit_BINARYz GenericTypeCompiler.visit_BINARY  s     5<AFU\,AGRHHr   c                .    d|j         r
d|j         z  pdz   S )N	VARBINARYrp  r  r  r  s      r   visit_VARBINARYz#GenericTypeCompiler.visit_VARBINARY  s     elDv/DJKKr   c                    dS )NBOOLEANr   r  s      r   visit_BOOLEANz!GenericTypeCompiler.visit_BOOLEAN  rU  r   c                t    |j         r| j        j        s|                     |dd          S  | j        |fi |S )Nru      )rr  )native_uuidr  supports_native_uuidrs  r  r  s      r   
visit_uuidzGenericTypeCompiler.visit_uuid  sN      	0(I 	0++E62+NNN"4?5//B///r   c                     | j         |fi |S r  )r  r  s      r   visit_large_binaryz&GenericTypeCompiler.visit_large_binary!      tu+++++r   c                     | j         |fi |S r  )r  r  s      r   visit_booleanz!GenericTypeCompiler.visit_boolean$      !t!%..2...r   c                     | j         |fi |S r  )rh  r  s      r   
visit_timezGenericTypeCompiler.visit_time'  r  r   c                     | j         |fi |S r  )rb  r  s      r   visit_datetimez"GenericTypeCompiler.visit_datetime*      "t"5//B///r   c                     | j         |fi |S r  )re  r  s      r   
visit_datezGenericTypeCompiler.visit_date-  r  r   c                     | j         |fi |S r  )r\  r  s      r   visit_big_integerz%GenericTypeCompiler.visit_big_integer0       t --"---r   c                     | j         |fi |S r  )rX  r  s      r   visit_small_integerz'GenericTypeCompiler.visit_small_integer3  r  r   c                     | j         |fi |S r  )rT  r  s      r   visit_integerz!GenericTypeCompiler.visit_integer6  r  r   c                     | j         |fi |S r  )rG  r  s      r   
visit_realzGenericTypeCompiler.visit_real9  r  r   c                     | j         |fi |S r  )r=  r  s      r   visit_floatzGenericTypeCompiler.visit_float<  s    t,,,,,r   c                     | j         |fi |S r  )rA  r  s      r   visit_doublez GenericTypeCompiler.visit_double?  r  r   c                     | j         |fi |S r  )rM  r  s      r   visit_numericz!GenericTypeCompiler.visit_numericB  r  r   c                     | j         |fi |S r  r~  r  s      r   visit_stringz GenericTypeCompiler.visit_stringE  r  r   c                     | j         |fi |S r  r  r  s      r   visit_unicodez!GenericTypeCompiler.visit_unicodeH  r  r   c                     | j         |fi |S r  r  r  s      r   
visit_textzGenericTypeCompiler.visit_textK  r  r   c                     | j         |fi |S r  r  r  s      r   visit_unicode_textz&GenericTypeCompiler.visit_unicode_textN  r  r   c                     | j         |fi |S r  r  r  s      r   
visit_enumzGenericTypeCompiler.visit_enumQ  r  r   c                0    t          j        d|z            )NzKCan't generate DDL for %r; did you forget to specify a type on this Column?r  r  s      r   r  zGenericTypeCompiler.visit_nullT  s$    #%*+
 
 	
r   c                N     | j         |                    | j                  fi |S r  )r  type_enginer  r  s      r   visit_type_decoratorz(GenericTypeCompiler.visit_type_decorator[  s,    t|E--dl;;BBrBBBr   c                     |j         di |S r6  )get_col_specr  s      r   visit_user_definedz&GenericTypeCompiler.visit_user_defined^  s    !u!''B'''r   r  )2r   r   r  r=  rA  rD  rG  rM  rQ  rT  rX  r\  r_  rb  re  rh  rk  rn  rs  rw  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r:  r:    s           " " "  	 	 		 	 	                     7 7 78 8 8: : :; ; ;7 7 7    I I IL L L  0 0 0, , ,/ / /, , ,0 0 0, , ,. . .0 0 0/ / /, , ,- - -. . ./ / // / // / /, , ,, , ,/ / /
 
 
C C C( ( ( ( (r   r:  c                  ,    e Zd Zd Zd Zd Zd Zd ZdS )StrSQLTypeCompilerc                `    	 |j         } || fi |S # t          $ r  | j        |fi |cY S w xY wr  )r  AttributeError_visit_unknown)r  r  r  r  s       r   r  zStrSQLTypeCompiler.processc  si    	2!&!9 &%d11b111  	4 	4 	4&4&u3333333	4s    --c                X    |                     d          r| j        S t          |          )Nr  )rl  r  r  )r  r0  s     r   __getattr__zStrSQLTypeCompiler.__getattr__k  s-    >>(## 	&&& %%%r   c                    |j         j        |j         j                                        k    r|j         j        S t          |          S r  )r  r   upperreprr  s      r   r  z!StrSQLTypeCompiler._visit_unknownq  s:    ?#u'?'E'E'G'GGG?++;;r   c                    dS r  r   r  s      r   r  zStrSQLTypeCompiler.visit_nullw  r  r   c                `    	 |j         } |di |S # t          $ r t          |          cY S w xY wr6  )r  r  r  )r  r  r  r  s       r   r  z%StrSQLTypeCompiler.visit_user_definedz  sV    	& -L  <%%"%%%  	 	 	;;	s    --N)r   r   r  r  r  r  r  r  r   r   r   r  r  b  s_        2 2 2& & &    & & & & &r   r  c                      e Zd ZddZdS )_SchemaForObjectCallable_SchemaForObjectCallable__objr   r  r   c                    d S r  r   )r  r  s     r   r  z!_SchemaForObjectCallable.__call__        r   N)r  r   r  r   r  r   r   r   r  r    s        ......r   r  c                      e Zd ZddZdS )r7  r  r  r  r   c                    d S r  r   )r  r  s     r   r  z _BindNameForColProtocol.__call__  r  r   N)r  r  r  r   r  r   r   r   r7  r7    s        ::::::r   r7  c                     e Zd ZU dZeZeZeZ	de
d<   de
d<   de
d<    ej        d          Zde
d	<   	 d
Zde
d<   	 	 	 	 	 d8dZd Zd Zd9dZd9dZd Zd9dZd:dZd Zd;d<dZd;d=dZd  Zd>d!Z	 d;d?d&Z	 d;d@d)Zd;d*Z ej         d+          d>d,            Z!d>d-Z"d>d.Z#d/ Z$d0 Z%dAd1Z&d2 Z'	 d;d3Z(	 	 	 	 	 dBd4Z)d>d5Z*ej+        d6             Z,d7 Z-dS )Cr  z@Handle quoting and case-folding of identifiers based on options.r   initial_quotefinal_quotezMutableMapping[str, str]_stringsr#   r  r  Fr  _includes_none_schema_translater  NTc                    || _         || _        |p| j        | _        || _        | j        dz  | _        || _        || _        i | _        | j         j        dv | _	        dS )as  Construct a new ``IdentifierPreparer`` object.

        initial_quote
          Character that begins a delimited identifier.

        final_quote
          Character that ends a delimited identifier. Defaults to
          `initial_quote`.

        omit_schema
          Prevent prepending schema name. Useful for databases that do
          not support schemae.
        r7   )r   r   N)
r  r  r  escape_quoteescape_to_quoteomit_schemaquote_case_sensitive_collationsr  rk  r  )r  r  r  r  r  r  r  s          r   r  zIdentifierPreparer.__init__  so    . *&<$*<(#014&/N, $ 7 <
 !
r   c                    | j                             | j                   }|j                            | j                   d |v fd}||_        |_        |S )Nc                    | j         }| j        r;|r7|d|v sd|v rt          j        d|z            t	          d|pdz  d          S | j         S )Nr  r   zJSquare bracket characters ([]) not supported in schema translate name '%s'z__[SCHEMA_%s]_noneFr  )r#   _use_schema_mapr8   r  r1   )r  r   includes_nones     r   symbol_getterz@IdentifierPreparer._with_schema_translate.<locals>.symbol_getter  s    :D" 
"(8M(8#t*8:>?   ##tw7u    z!r   )r  __new__rw  rx  r  r  )r  r  prepr  r  s       @r   r  z)IdentifierPreparer._with_schema_translate  sm    ~%%dn55T]+++ 44	" 	" 	" 	" 	" "//<,r   c                     |d v r& j         st          j        d          d          d<    fd}t          j        d||          S )Nzschema translate map which previously did not have `None` present as a key now has `None` present; compiled statement may lack adequate placeholders.  Please use consistent keys in successive schema_translate_map dictionaries.r  c                    |                      d          }|v r	|         }n|dv rt          j        d          |}|s"j        j        }|st          j        d                              |          S )Nr7   )Nr  zschema translate map which previously had `None` present as a key now no longer has it present; don't know how to apply schema for compiled statement. Please use consistent keys in successive schema_translate_map dictionaries.zLDialect has no default schema name; can't use None as dynamic schema target.)r   r8   r2  r  default_schema_namer  r  )r  r   r  dr  s      r   r  z=IdentifierPreparer._render_schema_translates.<locals>.replace  s    771::Dqyy#$T7  ?**1=   $( # #'<#C ' *=   $$%5666r   z(__\[SCHEMA_([^\]]+)\]))r  r8   r2  rR  r  )r  r&  r  r  r  s   `   @r   r  z,IdentifierPreparer._render_schema_translates  s{     1997 -9   4AgJ	7 	7 	7 	7 	7 	72 v0'9EEEr   r  r  c                    |                     | j        | j                  }| j        r|                     dd          }|S )zEscape an identifier.

        Subclasses should override this to provide database-dependent
        escaping behavior.
        r  r  )r  r  r  r  r  r  s     r   _escape_identifierz%IdentifierPreparer._escape_identifier  s@     d/1EFF  	-MM#t,,Er   c                B    |                     | j        | j                  S )zCanonicalize an escaped identifier.

        Subclasses should override this to provide database-dependent
        unescaping behavior that reverses _escape_identifier.
        )r  r  r  r  s     r   _unescape_identifierz'IdentifierPreparer._unescape_identifier  s     }}T143DEEEr   c                t    |5|                     |          s t          j        d|d|j        d          |S )zkeyword sequence filter.

        a filter for elements that are intended to represent keyword sequences,
        such as "INITIALLY", "INITIALLY DEFERRED", etc.   no special characters
        should be present.

        .. versionadded:: 1.3

        NzUnexpected SQL phrase: z (matching against r  )r3  r8   r  r<  )r  r  rU  s      r   r)  z&IdentifierPreparer.validate_sql_phrase!  sN     syy'9'9""77CKKK)   r   c                L    | j         |                     |          z   | j        z   S )z~Quote an identifier.

        Subclasses should override this to provide database-dependent
        quoting behavior.
        )r  r  r  r  s     r   quote_identifierz#IdentifierPreparer.quote_identifier3  s0     %%e,,-	
r   c                    |                                 }|| j        v p<|d         | j        v p-| j                            t          |                     p||k    S )z5Return True if the given identifier requires quoting.r   )r_  reserved_wordsillegal_initial_characterslegal_charactersr3  r   )r  r  lc_values      r   r  z#IdentifierPreparer._requires_quotes@  sd    ;;==++ #Qx4::#(..s5zz:::# E!		
r   c                R    | j                             t          |                     S )zjReturn True if the given identifier requires quoting, but
        not taking case convention into account.)r  r3  r   r  s     r   r]  z1IdentifierPreparer._requires_quotes_illegal_charsJ  s$     (..s5zz::::r   forcer   c                \    |t          j        dd           |                     |          S )a  Conditionally quote a schema name.


        The name is quoted if it is a reserved word, contains quote-necessary
        characters, or is an instance of :class:`.quoted_name` which includes
        ``quote`` set to ``True``.

        Subclasses can override this to provide database-dependent
        quoting behavior for schema names.

        :param schema: string schema name
        :param force: unused

            .. deprecated:: 0.9

                The :paramref:`.IdentifierPreparer.quote_schema.force`
                parameter is deprecated and will be removed in a future
                release.  This flag has no effect on the behavior of the
                :meth:`.IdentifierPreparer.quote` method; please refer to
                :class:`.quoted_name`.

        NzThe IdentifierPreparer.quote_schema.force parameter is deprecated and will be removed in a future release.  This flag has no effect on the behavior of the IdentifierPreparer.quote method; please refer to quoted_name().0.9rM  )r&   rP  r  )r  r#   r	  s      r   r  zIdentifierPreparer.quote_schemaO  sD    .   !     zz&!!!r   r  c                J   |t          j        dd           t          |dd          }|`|| j        v r| j        |         S |                     |          r|                     |          | j        |<   n
|| j        |<   | j        |         S |r|                     |          S |S )a  Conditionally quote an identifier.

        The identifier is quoted if it is a reserved word, contains
        quote-necessary characters, or is an instance of
        :class:`.quoted_name` which includes ``quote`` set to ``True``.

        Subclasses can override this to provide database-dependent
        quoting behavior for identifier names.

        :param ident: string identifier
        :param force: unused

            .. deprecated:: 0.9

                The :paramref:`.IdentifierPreparer.quote.force`
                parameter is deprecated and will be removed in a future
                release.  This flag has no effect on the behavior of the
                :meth:`.IdentifierPreparer.quote` method; please refer to
                :class:`.quoted_name`.

        NzThe IdentifierPreparer.quote.force parameter is deprecated and will be removed in a future release.  This flag has no effect on the behavior of the IdentifierPreparer.quote method; please refer to quoted_name().r	  rM  r  )r&   rP  r^  r  r  r  )r  r  r	  s      r   r  zIdentifierPreparer.quotev  s    ,   !     w--=%%}U++((// 1+/+@+@+G+GDM%((+0DM%(}U++ 	((///Lr   c                >    | j         r|                     |          S |S r  )r  r  )r  collation_names     r   r  z#IdentifierPreparer.format_collation  s%    / 	"::n---!!r   c                    |                      |j                  }|                     |          }| j        s|r||                     |          dz   |z   }|S r  )r  r   r  r  r  )r  rg  rq  r   r  s        r   r\  z"IdentifierPreparer.format_sequence  sk    zz(-((11(;;  	D	D !,$$%566<tCDr   r  
Label[Any]r   r=  c                :    |                      |p|j                  S r  r  r   )r  r  r   s      r   r  zIdentifierPreparer.format_label  s     zz$,%*---r   r  Optional[AliasedReturnsRows]c                l    ||J |                      |j                  S |                      |          S r  r
	  )r  r  r   s      r   r  zIdentifierPreparer.format_alias  s;     <$$$::ej)))::d###r   c                l    |p|j         }|                     |          r|                     |          }|S r  )r  r  r  )r  	savepointr   r  s       r   r-  z#IdentifierPreparer.format_savepoint  s>     '	  '' 	1))%00Er   zsqlalchemy.sql.namingc                    t           j        j        }|j        t          u r |                    ||j                  }|d S n|j        }|j        dk    r|                     ||          S | 	                    ||          S )Nrx  )_alembic_quote)
r&   r2  
sql_namingr   r,   _constraint_name_for_tabler   r  truncate_and_render_index_name#truncate_and_render_constraint_name)r  r   r	  namingr   s        r   r  z$IdentifierPreparer.format_constraint  s    *?j((44J, D |t  ?D$//66^ 7    ;;^ <   r   c                `    | j         j        p| j         j        }|                     |||          S r  )r  max_index_name_lengthrp   _truncate_and_render_maxlen_namer  r   r	  max_s       r   r	  z1IdentifierPreparer.truncate_and_render_index_name  s?    
 L. 2|1 	 44$
 
 	
r   c                `    | j         j        p| j         j        }|                     |||          S r  )r  max_constraint_name_lengthrp  r	  r	  s       r   r	  z6IdentifierPreparer.truncate_and_render_constraint_name  s?    
 L3 2|1 	 44$
 
 	
r   c                   t          |t          j                  rAt          |          |k    r-|d|dz
           dz   t	          j        |          dd          z   }n| j                            |           |s|S |                     |          S )Nr   rY  r  )	r  r   rE   r  r&   md5_hexr  validate_identifierr  )r  r   r	  r	  s       r   r	  z3IdentifierPreparer._truncate_and_render_maxlen_name  s    dH566 	34yy4AqL)C/$,t2D2DRSS2IIL,,T222 	$K::d###r   c                ,    |                      |          S r  )r  r  s     r   r  zIdentifierPreparer.format_index  s    %%e,,,r   c                    ||j         }|                     |          }|                     |          }| j        s|r|r|                     |          dz   |z   }|S )z'Prepare a quoted table and schema name.Nr  )r   r  r  r  r  )r  r   rq  r   rW  r  s         r   r  zIdentifierPreparer.format_table  su     <:DD!!11%88 	HJ 	H3C 	H&&'7883>GFr   c                ,    |                      |          S )zPrepare a quoted schema name.r  rc  s     r   r  z IdentifierPreparer.format_schema   s     zz$r   c                    |/t          |t          j                  r|                    |          }|                     |          S )Prepare a quoted column name.)r  r   rE   r[  r  )r  r   rq  s      r   r  z$IdentifierPreparer.format_label_name%  sF     J(+%
 %
 >>(++Dzz$r   c                   ||j         }|/t          |t          j                  r|                    |          }t          |dd          sM|r6|                     |j        ||          dz   |                     |          z   S |                     |          S |r#|                     |j        ||          dz   |z   S |S )r%	  Nr  F)rq  r   r  )	r   r  r   rE   r[  r^  r  r   r  )r  r   r  r   
table_namerq  rq  s          r   r  z IdentifierPreparer.format_column3  s    <;DJ(+%
 %
 >>(++Dv|U33 	 	(%%* &    jj&&	' zz$'''
  	%%* &    	 r   c                    |                      |          }| j        s0|r.|r,|                     |          |                     |d          fS |                     |d          fS )z(Format table name and schema as a tuple.Fr  )r  r  r  r  )r  r   rq  r  s       r   rx  z#IdentifierPreparer.format_table_seq`  s      11%88 	AJ 	A3C 	A!!"233!!%E!:: 
 %%e%>>@@r   c                    d | j         | j        |                     | j                  fD             \  }}}t          j        d|||dz            }|S )Nc              3  >   K   | ]}t          j        |          V  d S r  )rR  rS  r  s     r   r1  z4IdentifierPreparer._r_identifiers.<locals>.<genexpr>s  s>       )
 )
 IaLL)
 )
 )
 )
 )
 )
r   zM(?:(?:%(initial)s((?:%(escaped)s|[^%(final)s])+)%(final)s|([^\.]+))(?=\.|$))+)initialfinalr  )r  r  r  rR  rT  )r  r+	  r,	  escaped_finalrs        r   _r_identifiersz!IdentifierPreparer._r_identifiersq  s    )
 )
 " ''(899)
 )
 )
% J$ "EmLLM
 
 r   c                h      j         } fdd |                    |          D             D             S )z:Unpack 'schema.table.column'-like strings into components.c                :    g | ]}                     |          S r   )r  r  s     r   r  z;IdentifierPreparer.unformat_identifiers.<locals>.<listcomp>  s7     
 
 
 %%a((
 
 
r   c                    g | ]	\  }}|p|
S r   r   )r   ar_  s      r   r  z;IdentifierPreparer.unformat_identifiers.<locals>.<listcomp>  s     @@@Aaf1@@@r   )r/	  findall)r  identifiersr.	  s   `  r   unformat_identifiersz'IdentifierPreparer.unformat_identifiers  sR     
 
 
 
@@;)?)?@@@
 
 
 	
r   )r  Nr  TF)r  r   r  r   )r  r   r  r  r  )r#   r   r	  r   r  r   )r  r   r	  r   r  r   )T)r  r	  r   r=  r  r   )r  r	  r   r=  r  r   )TN)FNNFN).r   r   r  r  RESERVED_WORDSr  LEGAL_CHARACTERSr  ILLEGAL_INITIAL_CHARACTERSr  r  r?  
attrgetterr  r  r  r  r  r  r  r)  r  r  r]  r  r  r  r\  r  r  r-  r&   rB  r  r	  r	  r	  r  r  r  r  r  rx  r>  r/	  r6	  r   r   r   r  r    s	        JJ#N'!;&&&&2E(2Eh2O2OOOOO -2#1111
 (,"
 "
 "
 "
H  0'F 'F 'FR
 
 
 
F F F F  $
 
 
 

 
 
 
; ; ;
%" %" %" %" %"N2 2 2 2 2h" " "    8<. . . . . JN$ $ $ $ $    T011   21,

 

 

 



 

 

 


$ 
$ 
$- - -                " + + + +ZA A A A" 
  "
 
 
 
 
r   r  )r  
__future__r   r}  collections.abcabcr  r@  enumr   r  r  r?  rR  timer   rd  r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r    r!   r"   r#   r$   r%   r&   rS  _typingr(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   type_apir4   visitorsr5   r6   r8   r9   util.typingr:   r;   r<   
annotationr=   r>   r?   r  r@   ry  rA   dmlrB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   engine.cursorrU   engine.interfacesrV   rW   rX   rY   rZ   r[   r\   r]   r^   r   _FromHintsTyper7	  rT  Ir8	  LEGAL_CHARACTERS_PLUS_SPACEr  r   r9	  r*  r,  r/  UNICODEr  r  rm  rn  r  or_rl  mulr  modnegltlenegtgeeqis_distinct_fromis_not_distinct_from	concat_opr  not_match_opr  r  rT  r  r  rI  rJ  r   existsdistinct_opinvany_opall_opdesc_opasc_opnulls_first_opnulls_last_opbitwise_xor_opbitwise_or_opbitwise_and_opbitwise_not_opbitwise_lshift_opbitwise_rshift_opr  r   r   r   r   r   r   r   r   r   r   r   cuberollupgrouping_setsr   r  r8  _CompoundSelectKeywordr   	UNION_ALLr   
EXCEPT_ALLr   INTERSECT_ALLr9  r   r  r  r  r  r  r  r  r%  r:  rJ  rW  re  rj  r3  rk  rl  rm  rn  
namedtuplerp  r  EnsureKWArgr  BinaryElementRoleCompilerColumnElementr  r	  r  rH  ro  r:  r  r  r7  r  r   r   r   <module>rt	     s    " # " " " " "     ) ) ) ) ) )                    				                                                                    ! ! ! ! ! !                                                                                                                                     & & & & & &                         2 2 2 2 2 2             # # # # # # ! ! ! ! ! !                         % % % % % %                         ! ! ! ! ! ! " " " " " " # # # # # #	 ";++++++,,,,,,""""""######))))))******''''''&&&&&&''''''######......//////&&&&&&++++++''''''""""""'''''',,,,,,444444<<<<<<::::::<<<<<<======333333======CCCCCC++++++::::::lC'(_ _ _B 2:.55 (bj):BDAA ;;eeArll;;;AA3%HH rz<bd  rz<bd  rz5rt<<bjA2:NN"*92:FF$ "$ .NG. M6. M5	.
 M5. M5. M5. M3. L%. L&. L&. L%. L&. L%.  4.  "$<!." #.$ 	%. .& M'.( OV).* +., -.. OX/.0 M61.2 M63.4 j5.6 {7.: i;.< ;=.> M6?.@ fA.B fC.F wG.H fI.J nK. .L ]eUec[. .	b 
NN!4N.hyNNFNFh_-	    & ""$( & %+W%/%,h%0,%/%3_        >         !             
            i   $ $ $ $ $1 $ $ $ $: : : : :J : : :zt t t t t
 t t tn    Z   2! ! ! ! !; ! ! !$    G        g   . FKUF F B
&l
?# ?# ?# ?# ?#''w6HII ?# ?# ?#DH' H' H' H' H' H' H' H'VF F F F F4# F F F0    	C ("@  2#
 #
 #
 #
 #
	C ("@#
 #
 #
L_T
 _T
 _T
 _T
 _T
( _T
 _T
 _T
Dil
 l
 l
 l
 l
[ l
 l
 l
^X X X X X( X X Xvj( j( j( j( j(, j( j( j(Z& & & & &, & & &B/ / / / /x / / /; ; ; ; ;h ; ; ;
 
 
 
 
 
 
 
 
 
r   