
    hIf                      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/l0m<Z< dd0l=m>Z> d1d2l&m?Z? d1d&l&m1Z1 d1d3l1m@Z@ d1d4lAmBZB d1d5lAmCZC d1d6lAmDZD d1d7lAmEZE ejH                  r>dd8lFmGZG dd9l'mHZH dd:l'mIZI dd;l'mJZJ dd<lKmLZL dd=lMmNZN dd>lOmPZP dd?lOmQZQ dd@lOmRZR ddAlOmSZS ddBlOmTZT ddCl*mUZU ddDl*mVZV ddEl*mWZW ddFl*mXZX ddGl*mYZY ddHl*mZZZ ddIl*m[Z[ ddJl*m\Z\ ddKl*m]Z] ddLl*m^Z^ ddMl+m_Z_ ddNl.m`Z` ddOl.maZa ddPl.mbZb ddQl.mcZc ddRl.mdZd ddSl.meZe ddTl.mfZf ddUl/mgZg ddVl/mhZh ddWl/miZi ddXl/mjZj ddYl/mkZk ddZl/mlZl dd[l/mmZm dd\l/mnZn dd]l/moZo dd^lpmqZq dd_lpmrZr dd`lpmsZs ddalpmtZt ddbl=muZu d1dclvmwZw d1ddlxmyZy d1delxmzZz d1dflxm{Z{ d1dglxm|Z| d1dhlxm}Z} d1dilxm~Z~ d1djlxmZ d1dklxmZ d1dllxmZ edmef   Zh dnZ ej
                  doej                        Z ej
                  dpej                        Z eddq      D  ch c]
  }  e|        c} j                  drg      Z ej
                  dsej                        Z ej
                  dsej                        Z ej
                  dtej                        Z ej
                  duej                        Z ej
                  dvej                        ZdwZedxdydzd{d|d}Zi e,j(                  d~e,j*                  de,j,                  de,j.                  de,j0                  de,j2                  de,j4                  de,j6                  de,j8                  de,j:                  de,j<                  de,j>                  de,j@                  de,jB                  de,jD                  de,jF                  de,jH                  di e,jJ                  de,jL                  de,jN                  de,jP                  de,jR                  de,jT                  de,jV                  de,jX                  de,jZ                  de,j\                  de,j^                  de,j`                  de,jb                  de,jd                  de,jf                  de,jh                  de,jj                  de,jl                  de,jn                  de,jp                  de,jr                  de,jt                  de,jv                  de,jx                  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τ deC      ZdZded<   dZded<   d1Zded<   dZded<    G dڄ deE      Z G d܄ dedެ߫      Z G d de      Z G d de      Z G d de      Z G d de@      Z G d de	      Z G d de	      Z ee      \  ZZZZ G d d ej                  dddg            Z G d d      Z G d de1j                        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  de      Z G d deC      Z G d deC      Z G d d      Zyc c} w (  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)NO_ARG)quoted_name)	TupleType)prefix_anon_map   )exc)FastIntFlag)Literal)Protocol)Self)	TypedDict)_AnnotationDict)_AmbiguousTableNameMap)CompileState)
Executable)CacheKey)ExecutableDDLElement)Insert)Update)
UpdateBase)UpdateDMLState)
ValuesBase)_truncated_label)BinaryExpression)BindParameter)ClauseElement)ColumnClause)ColumnElement)False_)Label)Null)True_)Function)Column)
Constraint)ForeignKeyConstraint)Index)PrimaryKeyConstraint)Table)UniqueConstraint)_ColumnsClauseElement)AliasedReturnsRows)CompoundSelectState)CTE)
FromClause)NamedFromClause)ReturnsRows)Select)SelectState)_BindProcessorType)TypeDecorator)
TypeEngine)UserDefinedType)	Visitable)CursorResultMetaData)_CoreSingleExecuteParams)_DBAPIAnyExecuteParams)_DBAPIMultiExecuteParams)_DBAPISingleExecuteParams)_ExecuteOptions)_GenericSetInputSizesType)_MutableCoreSingleExecuteParams)Dialect)SchemaTranslateMapTyperY   >^   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_ $]+$
   $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                  @    e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   y	)
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.

    strkeynamenameTuple[Any, ...]objectsTypeEngine[Any]typeN__name__
__module____qualname____doc____annotations__     @D:\EasyAligner\venv\Lib\site-packages\sqlalchemy/sql/compiler.pyr   r   k  s1     L;
I% r  r   c                  (    e Zd Z	 	 	 	 	 	 	 	 	 	 ddZy)_ResultMapAppenderc                     y Nr  selfr   r   r  type_s        r  __call__z_ResultMapAppender.__call__  s     r  N)
r   r   r   r   r  zSequence[Any]r  r  returnNoner  r  r  r  r  r  r  r  r    s7      	
  
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<   y)_BaseCompilerStackEntryzSet[FromClause]asfrom_fromscorrelate_fromsr[   r$   Nr  r  r  r
  r  r  r  r  r    s    !!$$r  r  c                  @    e Zd ZU ded<   ded<   ded<   ded<   ded	<   y
)_CompilerStackEntryr:   compile_stateboolneed_result_map_for_nestedneed_result_map_for_compoundr[   select_0Select[Any]insert_from_selectNr"  r  r  r  r$  r$    s      $$"&&##r  r$  F)totalc                  r    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y)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   	statementrd   
parameters%Mapping[str, _BindProcessorType[Any]]
processorsOptional[Sequence[str]]positiontupzMapping[str, List[str]]parameter_expansionc                      j                   t        j                  d      t         fd j                   D              S )zrTuple of positional parameters, for statements that were compiled
        using a positional paramstyle.

        z.statement does not use a positional paramstylec              3  <   K   | ]  }j                   |     y wr  r0  ).0keyr  s     r  	<genexpr>z6ExpandedState.positional_parameters.<locals>.<genexpr>  s     F5EcT__S)5Es   )r4  r2   InvalidRequestErrortupler  s   `r  positional_parametersz#ExpandedState.positional_parameters  s@     #))@  FT5E5EFFFr  c                    | j                   S )z.synonym for :attr:`.ExpandedState.parameters`.r8  r>  s    r  additional_parametersz#ExpandedState.additional_parameters  s     r  N)r  r  )r  rd   )r  r  r  r	  r
  propertyr?  rA  r  r  r  r.  r.    si    " N=(( 65+(( 10 	G 	G  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<   y)_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_columnsr3  sentinel_param_keysimplicit_sentinelembed_values_counter)r  r  r  r	  r
  rK  rL  rN  rO  rP  rQ  rR  r  r  r  rD  rD    s     
  87M#&&
 %*T) ',t+ 9=5< !"#! 4807  $t#	 "'$&	r  rD  c                  v    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<   y)_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_statementre   replaced_parameters#Optional[_GenericSetInputSizesType]processed_setinputsizesz#Sequence[_DBAPISingleExecuteParams]batchzSequence[Tuple[Any, ...]]sentinel_valuesrI  current_batch_sizebatchnumtotal_batchesr&  rows_sortedis_downgradedNr  r  r  r  rT  rT  ^  sD    
 //@@....Mr  rT  c                  B    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y)	InsertmanyvaluesSentinelOptszcbitflag enum indicating styles of PK defaults
    which can work as implicit sentinel columns

    r   r1            @   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  ra  ra  w  sE    
 MMHH%08;%(99 r  ra  c                      e Zd ZdZ	 dZ	 dZy)CompilerStater   r   r1   N)r  r  r  	COMPILINGSTRING_APPLIEDNO_STATEMENTr  r  r  ro  ro    s     I=N Lr  ro  c                  ,    e Zd ZdZdZ	 dZ	 dZ	 eez  Zy)Lintingzrepresent preferences for the 'SQL linting' feature.

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

    r   r   r1   N)r  r  r  r	  
NO_LINTINGCOLLECT_CARTESIAN_PRODUCTSWARN_LINTINGFROM_LINTINGr  r  r  rt  rt    s5     J!" L2-<Lr  rt  c                       e Zd ZdZddZddZy)
FromLinterzKrepresents current state for the "cartesian product" detection
    feature.Nc                  	 | j                   }|syt        | j                        }t        |      }||}|j                  |       n|j	                         }t        j                  |g      }|rg|re|j                         	|j                  	       |D ch c]	  }	|v s| }}|j                  	fd|D               |j                  |       |r|re|r||fS yc c}w )NNNc              3  H   K   | ]  }||j                              y wr  )index)r9  edgenodes     r  r;  z"FromLinter.lint.<locals>.<genexpr>  s#     NIDTdjj&6"67I   ")fromsr~   edgesremovepopcollectionsdequepopleftdiscard
extendleftdifference_update)
r  startr  r  the_rest
start_withstackr  	to_remover  s
            @r  lintzFromLinter.lint  s    

DJJu:JOOJ'!J!!:,/==?DT" +0@%$44<%I@ NINN##I.   Z'' As   	C Cc                      j                         \  }}|rX|}|rSd}dj                   fd|D              }|j                  || j                  |         }t	        j
                  |       y y y )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  D   K   | ]  }d j                   |    d   yw)"N)r  )r9  from_r  s     r  r;  z"FromLinter.warn.<locals>.<genexpr>  s(      &:?a

5)*!,%    )	stmt_typer  r  )r  r   r   r  r&   warn)r  r  r  r  r  template	froms_strmessages   `       r  r  zFromLinter.warn  s    #yy{* E7  !II &:?& 	 #//'#**Z0 *  		'"!  r  r  )SELECT)r  r  r  r	  r  r  r  r  r  rz  rz    s    #J#r  rz  r  r  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*d#       Zd+d$Zd,d%Z	 	 	 d-	 	 	 	 	 	 	 d.d&Zed'        Z xZ S )/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   stringro  stateFzOptional[CursorResultMetaData]_cached_metadataz"Optional[List[ResultColumnsEntry]]_result_columns Optional[SchemaTranslateMapType]schema_translate_maprh   execution_optionsIdentifierPreparerpreparerr8   _annotationszOptional[CompileState]r%  dml_compile_stateOptional[CacheKey]	cache_keyfloat	_gen_timec                   || _         | j                   j                  | _        |r'|| _        | j                  j	                  |      | _        |t
        j                  | _        || _        |j                  | _
        |j                  | _        | j                  r)t        rt        |t              sJ |j                  | _         | j"                  | j                  fi || _        |r/|J | j                  j'                  | j$                  |      | _        t
        j(                  | _        nt
        j*                  | _        t-               | _        y)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)dialectidentifier_preparerr  r  _with_schema_translatero  rp  r  r/  supports_executioncan_executer  r   
isinstancer;   _execution_optionsr  processr  _render_schema_translatesrq  rr  r   r  r  r  r/  r  render_schema_translatecompile_kwargss         r  __init__zCompiled.__init__K  s   4 88(<D% MM@@$DM  &00DJ&DN(;;D ) 6 6D %i<<<)2)E)E&&$,,t~~HHDK&+777"mmEEKK!5 '55DJ&33DJ%r  c                @    | j                          t        | 	         S r  )_init_compiler_clssuper__init_subclass__)cls	__class__s    r  r  zCompiled.__init_subclass__  s     w(**r  c                     y r  r  r  s    r  r  zCompiled._init_compiler_cls  s    r  c                ~    | j                   r|j                  | ||      S t        j                  | j                        r  )r  _execute_compiledr2   ObjectNotExecutableErrorr/  )r  
connectiondistilled_paramsr  s       r  _execute_on_connectionzCompiled._execute_on_connection  s@     //&(9  ..t~~>>r  c                B    t        j                  | t        |            |r  r2   UnsupportedCompilationErrorr  r  elementerrkws       r  visit_unsupported_compilationz&Compiled.visit_unsupported_compilation  s    --dDM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'.

        NotImplementedErrorr>  s    r  sql_compilerzCompiled.sql_compiler  s     "##r  c                (     |j                   | fi |S r  _compiler_dispatch)r  objkwargss      r  r  zCompiled.process  s    %s%%d5f55r  c                T    | j                   t        j                  u r| j                  S y)z3Return the string text of the generated SQL or DDL.r  )r  ro  rq  r  r>  s    r  __str__zCompiled.__str__  s#     ::555;;r  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  paramsextracted_parametersescape_namess       r  construct_paramszCompiled.construct_params  s     "##r  c                "    | j                         S )z0Return the bind params for this compiled object.r  r>  s    r  r  zCompiled.params  s     $$&&r  )
r  rk   r/  r  r  r  r  r&  r  Mapping[str, Any])r  r  r  SQLCompiler)r  rb   r  r   r  r   r  r   NNTr  "Optional[_CoreSingleExecuteParams]r  &Optional[Sequence[BindParameter[Any]]]r  r&  r  z)Optional[_MutableCoreSingleExecuteParams])!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  rB  r  r  r  r  r  __classcell__r  s   @r  r  r    s   
 *.I&-FC4-FF7;4;:>O7>=A:A)-8
 ! $(OOL/3,0M)0 15-4	 %)I!(	  BF(-,>D,>,>,@7(7( +7( ?	7(
 "&7( *7(r+  ?L $ $6 6:GK!	$2$ E$ 	$
 
3$ ' 'r  r  c                  <    e Zd ZdZdZddZddZ	 	 	 	 	 	 	 	 d	dZy)
TypeCompilerz2Produces DDL specification for TypeEngine objects.z	visit_\w+c                    || _         y r  )r  )r  r  s     r  r  zTypeCompiler.__init__  s	    r  c                    |j                   rE| 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  sU    ""!!U%;%;;**4<<+<+<=E'u''333r  c                0    t        j                  | |      |r  )r2   r  r  s       r  r  z*TypeCompiler.visit_unsupported_compilation  s     --dG<#Er  N)r  rk   )r  r  r  r   r  r   )r  r   r  	Exceptionr  r   r  r   )r  r  r  r	  ensure_kwargr  r  r  r  r  r  r  r    s>    <L4FF!*F25F	Fr  r  c                  F    e Zd ZdZdZdZd	dZed        Zed        Z	d Z
y)
_CompileLabelz;lightweight label object which acts as an expression.Label.labelr  r   
_alt_namesc                6    || _         || _        |f|z   | _        y r  r  )r  colr   	alt_namess       r  r  z_CompileLabel.__init__  s    	&9,r  c                .    | j                   j                  S r  r  	proxy_setr>  s    r  r	  z_CompileLabel.proxy_set      ||%%%r  c                .    | j                   j                  S r  r  r  r>  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  rB  r	  r  r  r  r  r  r   r     sD     FN/I-
 & & ! !r  r   c                  J    e Zd ZdZdZdZd Zed        Zed        Z	d Z
d Zy	)
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                4    || _         |j                  | _        y r  r  )r  r  s     r  r  zilike_case_insensitive.__init__  s    !,,r  c                .    | j                   j                  S r  r  r>  s    r  r	  z ilike_case_insensitive.proxy_set	  r
  r  c                .    | j                   j                  S r  r  r>  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                J    t        | j                  j                  |            S r  )r  r  _with_binary_element_type)r  r  s     r  r  z0ilike_case_insensitive._with_binary_element_type  s!    %LL2259
 	
r  N)r  r  r  r	  r  r  r  rB  r	  r  r  r  r  r  r  r  r    sJ    	 6N'I- & & ! !
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jJ                  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^                  e1jd                   dPe0jd                         Z3e4dQ        Z5e4dR        Z6ddde7df	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddTZ8e9ddU       Z:ejv                  ddV       Z<e9dW        Z=e9dX        Z>e9dY        Z?ej                  ddZ       ZAej                  d	d[       ZCeDj                  d\        ZFd] ZGd^ ZHej                  	 	 d
d_       ZId` ZJe9dda       ZK	 	 d	 	 	 	 	 ddbZL	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddcZMej                  dd        ZNe9de        ZO	 d	 	 	 	 	 ddfZP ej                  dg      dh        ZRdie	dj<   ej                  ddk       ZSej                   ej                  dl      dm               ZTej                   ej                  dl      dn               ZUddoZVdp ZWddqZXdr ZY	 ddsZZ	 ddtZ[	 	 	 	 	 dduZ\dv Z]dw Z^	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddxZ_dy Z`dz Zad{ Zbd| Zcd} Zdd~ ZeddZf	 ddZgddZhddZiddZjd Zkd Zld Zmd Znd Zod Zpd Zqd Zrd Zsd Ztd Zud Zvd Zwd Zx	 d	 	 	 	 	 	 	 ddZyd Zzd Z{ddZ|	 ddZ}d Z~d Z	 ddZd Zd Zd Zd Zd Zd Zd Zd Z	 ddZd Z	 	 	 	 d dZd Zd Zd Zd Zd Z	 d	 	 	 	 	 	 	 	 	 d!dZd Zd Zej                  d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z	 	 	 	 	 	 	 	 d"dZ	 	 	 	 	 	 	 	 d"dZ	 	 	 	 	 	 	 	 d"dÄZ	 	 	 	 	 d#dĄZdń ZedfdƄZ	 	 	 	 	 	 d$dǄZdȄ Z	 	 	 	 	 	 d%dɄZd&dʄZ	 	 	 	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(d˄Zd̄ Zddddd ejl                  d      f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d)d̈́Zd΄ Zdτ Z	 	 	 	 	 	 	 	 d*dЄZdф Zd҄ ZddӄZdԄ ZddՄZdք Zdׄ Z	 	 	 	 	 	 	 	 	 	 d+d؄Z	 ddلZ	 	 	 	 	 	 	 d,dڄZdۄ Zd܄ Z	 	 	 	 	 	 d-d݄Zdބ Zd߄ Zde	d<   eʐj                  s" ej                  d e"       fd e"       fg      Z	 ddZdZdSe	d<   	 	 	 	 	 	 	 	 d.dZ	 	 	 	 d/dZd Zd Zd Z	 	 ddZd ZՐd0dZd Zd Zd Z	 	 	 	 	 	 	 	 	 	 d1dZd Z	 	 	 d2dZ	 	 	 	 	 	 	 	 d3dZݐddZd Z ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  i      Zej                  ej                  ej                  i      Z	 	 	 	 d4dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5dZ	 d6dZd Zd Zd Zd Z	 d	 	 	 	 	 	 	 d7dZd Zd  ZddZd Zd Zd Zy(8  r  z~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_matchr4  _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                $    | j                          y r  )_init_bind_translater  s    r  r  zSQLCompiler._init_compiler_clsC  s      "r  c                    t        j                  dj                  | j                              }t        j                  d| d      | _        | j                  | _        y )Nr  r*  r+  )reescaper   r-  compiler.  r/  )r  regs     r  r[  z SQLCompiler._init_bind_translateG  sF    ii > >?@!#auAJ!7$'$B$B!r  r   c                >   || _         || _        |r:|d   D 	ci c]  }	|	j                  |	 }
}	|d   D 	ci c]  }	|	|	g }}	||
f| _        || _        || _        i | _        t        j                         | _	        g | _
        g | _        |j                  | _        | j                  rH|j                  j                  d      x| _        }|r|j                  dk(  rdnd| _        t"        | _        nt&        |j                     | _        d| _        |j*                  xs |j,                  | _        t/               | _        i | _        i | _        t7        j8                  | ||fi | | j:                  s| j<                  s| j>                  rt@        rtC        |tD              sJ | j:                  s| j<                  rmt@        rtC        |tF              sJ |jH                  rd| _%        nA| j                  r5| j:                  r"| jL                  jN                  r|jP                  rd| _%        t&        |j                     | _)        |rK| jT                  jW                  |jT                  jY                         D ci c]  \  }}|dvr|| c}}       | jZ                  t\        j^                  u rm| j                  r-| j                  r| ja                          n| jc                          | jd                  r'| jg                  d	d
      }| ji                  |d       yyyc c}	w c c}	w c c}}w )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.

        r   r   r   r   r(  NT>   r  r  r  
positionalr>  rE  r?  Fr  _no_postcompile)_populate_self)5column_keysr  r:  rQ  for_executemanylintingr9  r&   column_dictr:  r  r  rb  
paramstyle
startswithrE  r@  _pyformat_templater?  BIND_TEMPLATESrU  label_lengthmax_identifier_lengthr0   anon_maptruncated_names_truncated_countersr  r  r1  r2  r0  r   r  r@   rB   _inlinerT  r  insert_executemany_returning_return_defaultsr>  __dict__updateitemsr  ro  rq  _process_numeric_process_positionalrF  r  #_process_parameters_for_postcompile)r  r  r/  r  rf  rg  rh  _supporting_againstr  bcksmckbmnbkvr0  s                   r  r  zSQLCompiler.__init__M  s   @ '"&/l3lAEE1HlD3$-aL1LqAsFLD1*.D&
  / 
 **, 
! ",,??'.'9'9'D'DY'OOD""--1AACs 3 -?D),:7;M;M,ND)	   AG$A$A 	 () <>35 $=f===DMMT]]!)Z888}} %i<<<$$"&DK))AA%66 #'DK*7+=+=>MM   !4 < < B B D D1	 qD D" ::555&&))+,,.''!22!&$( 3 

 88t 9  ( 6y 41Vs   LL,L
c                H    | j                   y| 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)rL  rF  r>  s    r  insert_single_values_exprz%SQLCompiler.insert_single_values_expr  s%     !!)))<<<r  c                    | j                   r| j                   S | j                  Dt        | j                        r/| j                  j                  D cg c]  }t	        |      r| c}S yc c}w )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

        N)r7  r/  r(   _all_selected_columnsr'   )r  cs     r  effective_returningzSQLCompiler.effective_returning  sl     ""***^^'F4>>,B ===A$Q' =  s   A*c                    | j                   S )zVbackwards compatibility; returns the
        effective_returning collection.

        )r  r>  s    r  	returningzSQLCompiler.returning  s     '''r  c                b    	 | 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  s;    <	M::b>,// 	MCD"L	Ms    	.).c                X    t        | j                        t        | j                        z   S r  )listr4  r5  r>  s    r  prefetchzSQLCompiler.prefetch6  s#    D(()D1E1E,FFFr  c                    i S r  r  r>  s    r  _global_attributeszSQLCompiler._global_attributes:  s    	r  c                f    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&   OrderedDictrU  rV  rW  rX  )r  rU  s     r  _init_cte_statezSQLCompiler._init_cte_state>  s:     *.)9)9);	 #% "$#r  c              #  h  K   | j                   | j                  }}g dc| _         | _        	 | j                  r| j                  d   }d|d<   nd}| j                   | j                  f |r|j                  d       ||c| _         | _        y# r|j                  d       ||c| _         | _        w xY ww)z;special API to support the use case of 'nested result sets'Fr  Tr'  N)r  rC  r  r  )r  result_columnsordered_columnsentrys       r  _nested_resultzSQLCompiler._nested_resultV  s        !! ( 79%3d3	zz

26:23&&(=(===		67 8D $"7 		67 8D $"7s   (B2=B (#B2$B//B2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                  rv| j                  j                         D ci c]  \  }}||
 }}}t        | j                        t        |      k(  sJ 	D cg c]  }|j                  ||       c}| _         n	| _         | j                  rg 	t        j                  | j                  || j                  j                         }| j                  j"                  D cg c]3  }|d   |d   t        j                  | j                  ||d         |d	   f5 }}| j                  j%                  ||
      | _        y y c c}}w c c}w c c}w )Nr   %sr   r   c                    | j                  d      }|rj                  |       S j                  | j                  d             | j                  d      S )Nr   r1   r   )r   append)mnormal_bindplaceholder	positionss     r  find_positionz6SQLCompiler._process_positional.<locals>.find_position{  sM    ''!*K  -""   ,wwqz!r  r   r   r1   r  rF  rH  )r  zre.Match[str]r  r   )r4  r  ro  rq  rE  r  rj  r]  sub_positional_patternr  rP  rx  lengetrL  rF  rH  _replace)
r  r  r  r  reverse_escaper   rF  rH  r  r  s
           @@r  rz  zSQLCompiler._process_positionaln  s   ####zz]99999&&&&<<""h.K<<**g555K		" ff$$mT[[
 ""/3/F/F/L/L/NO/Ntq!ad/NNOt../3~3FFFF;D ;D4""4.9 D  )D!!I!#((&&99" //BB" CA aDaDFF433]AaDIaD	 C  " &*%;%;%D%D#5#5 &E &D"% " P "s   G1G78G<c                t     j                   sJ  j                  t        j                  u sJ d}i  j                  r\ j
                  Pt        j                   fd j                  j                         D         j                  j                               }n j                  j                         }|D ]R  }|v r j                  |   }| j                  v s| j                  v rd |<   9 j                   | }|dz  }||<   T | _        t               _         j"                  rYt%              }j'                         D ci c]"  \  }} j"                  j)                  ||      |$ c}}t%              |k(  sJ  j*                  j-                  fd j.                         _         j                  rl j                  j0                  z  }	 j                  j2                  D 
cg c]  }
|
d   |
d   d|
d   f }}
 j                  j5                  |	|       _        y y c c}}w c c}
w )Nr   c              3  >   K   | ]  }|j                   vr|  y wr  )rR  )r9  r   r  s     r  r;  z/SQLCompiler._process_numeric.<locals>.<genexpr>  s'       84#9#99  8   c                ,    | j                  d         S Nr   r   r  	param_poss    r  <lambda>z.SQLCompiler._process_numeric.<locals>.<lambda>  s    i
+r  r   r  r  r  )rE  r  ro  rq  rL  rR  	itertoolschainr:  valuesr9  rO  rN  r@  next_numeric_posr  r4  rP  r  rx  r  _pyformat_patternr  r  rF  rH  r  )r  numr   	bind_namebindph
len_beforer   posrF  r  rH  r  s   `           @r  ry  zSQLCompiler._process_numeric  sN   """"zz]99999$&	!!d&<&<&H OO $ 6 6 8
 &&(E OO**,EII%::i(D0004666 (,	)$;;<SEBq')	)$   !$	?""YJ "+!2!2ID# ''++D$7<!2I y>Z/// ,,00+T[[
 !! &&99  //BB"BA 1qtT1Q4(B  "
 &*%;%;%D%D#5#5	 &E &D" "$"s   'H/3H5c                f      fd j                   D        D ci c]
  \  }}||| c}}S c c}}w )Nc           	   3    K   | ]  }j                   |   |j                  j                  s%|j                  j                  j                        n5t        fd t        t        |j                        j                  D              f  yw)c              3  T   K   | ]  }|j                  j                         ! y wr  )_cached_bind_processorr  )r9  	elem_typer  s     r  r;  z9SQLCompiler._bind_processors.<locals>.<genexpr>.<genexpr>  s,      #.$	 &<<T\\J.$s   %(N)	r:  r  _is_tuple_typer  r  r=  r   r/   types)r9  	bindparamr  s     r  r;  z/SQLCompiler._bind_processors.<locals>.<genexpr>  s       "1I OOI.  )~~<< "==dllK" #-1 )9>>.#e.$#  "1s   B
B)r:  )r  r:  values   `  r  _bind_processorszSQLCompiler._bind_processors  sL     "&

U   # J
 	
 
s   -c                2    t        | j                        dkD  S r  )r  r  r>  s    r  is_subqueryzSQLCompiler.is_subquery  s    4::""r  c                    | S r  r  r>  s    r  r  zSQLCompiler.sql_compiler  s    r  c                L    | j                  ||d      }| j                  |      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

        Trc  )r  r{  )r  r  r  r0  s       r  construct_expanded_statez$SQLCompiler.construct_expanded_state  s:     **%  + 


 77
 	
r  c                   | j                   rF|sD| j                  J |st        | j                  j                        S t	        j
                  d      |xr t        | j                        }|rq| j                  t	        j                  d      | j                  d   }| j                  }	|	J |	\  }
}t        ||      D ci c]  \  }}|
|   D ]  }||  }}}}nd}|ri }| j                  j                         D ]  \  }}|r| j                  j                  ||      n|}|j                  |v r||j                     ||<   G||v r	||   ||<   T|rX|j                   rL|r&t	        j
                  d|j                  |fz  d      t	        j
                  d|j                  z  d      |r|j                  ||      }n|}|j"                  r|j$                  ||<   |j&                  ||<    |S i }| j                  j                         D ]  \  }}|r| j                  j                  ||      n|}|rX|j                   rL|r&t	        j
                  d|j                  |fz  d      t	        j
                  d|j                  z  d      |r|j                  ||      }n|}|j"                  r|j$                  ||<   |j&                  ||<    |S c c}}}w )	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   z@A value is required for bind parameter %r, in parameter group %dcd3x)codez)A value is required for bind parameter %r)rF  rG  dictr0  r2   r<  r&  rP  r  CompileErrorrQ  zipr:  rx  r  r:  requiredcallableeffective_valuer  )r  r  r  r  _group_number_checkrd  has_escaped_namesorig_extracted
ckbm_tupler  r$  r}  	extractedr  resolved_extractedpdr  r   escaped_namevalue_params                        r  r  zSQLCompiler.construct_params-  s?    ##O44@@@D==HHII--4  )JT$2I2I-J ~~%&&J 
 "&!233J))) GD! %(8L$M"$MLAy GD i# $M  " "&B#'??#8#8#:	4 ) ++//d;  ==F*'-imm'<B|$V^'-d|B|$	 2 2$!554(}}m<= "(	  "55G'mm,!'  *&8&<&<%y' '0 ))+6+F+F<(+6+<+<<(K $;L IB#'??#8#8#:	4 ) ++//d;  i00$!554(}}m<= "(	  "55G'mm,!'  &"4"8"8I"NK"+K%%'2'B'BB|$'2'8'8B|$= $;@ Ig"s   Kc                  	 | j                   j                  	j                  j                  	fd}i }| j                  }| j
                  D ]n  }||v r|j                  j                  r<t        t        |j                        j                  D cg c]
  } ||       c}||<   Z ||j                        ||<   p |S c c}w )Nc                f    | j                        j                        }||vr|v r|S y 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  sH    009HHOF ""*fM.I"*f.Er  )r  include_set_input_sizesexclude_set_input_sizesr  rN  r:  r  r  r   r/   r  )
r  r  
inputsizesrN  r  r  r  r  r  r  s
         @@@@r  _get_set_input_sizes_lookupz'SQLCompiler._get_set_input_sizes_lookup  s    ,,7777
	 
!%!<!<I22~~,,  $Iy~~>DD)D  $D)
9%
 )4INN(C
9% ) )s   C
c                &    | j                  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  r>  s    r  r  zSQLCompiler.params  s     $$E$22r  c                   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                         }| j                  }|D ]  |r|j                        n}| j                     }|| j                  v r*|vr%| j                  ||j                  |            |<   a|| j                   v r|v r|	|   }d}n3|j                        }| j#                  |||      }|\  }}||	|<   ||<   |j$                  r|j'                  |       |j(                  j*                  r*|J |j'                  fdt-        |d      D               n|j'                  fd|D               |
|
j/                  d |D               n||j/                  d	 |D               |D cg c]  \  }}|	 c}}|<   w|{|j1                          fd
}t3        j4                  | j6                  ||      }|
l|J t-        |
| j8                        D ci c]  \  }}|| j:                   |  c}}| j<                  j5                  fd|      }|j/                  |
       t?        |||||      }|rR|| _         || _        |j@                  | _        | j                  rtC        |j                  xs d      nd| _        || _"        |S c c}}w c c}}w )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.

        Nr1  z/Mapping[str, Sequence[_BindProcessorType[Any]]]render_literal_valuec              3     K   | ]?  \  }}t        |d       D ]+  \  }}v r"   |d z
     d|d|   |d z
     f - A yw)r   Nr$  )	enumerate)r9  ituple_elementjr$  r   tuple_processorss        r  r;  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>N  sy      	.
 5I 0=(1-(C1#'77 0 6q1u = I /3Aq 9 0 6q1u =
 )D 5Is   AAr   c              3  :   K   | ]  \  }}v r	|   f  y wr  r  )r9  r:  r$  r   single_processorss      r  r;  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>Y  s1      .*3Q#'88 !"3D"9:*3   c              3  &   K   | ]	  \  }}|  y wr  r  r9  r   r$  s      r  r;  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>_  s      309WT1D	   c              3  &   K   | ]	  \  }}|  y wr  r  r  s      r  r;  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>f  s     .M9at9r   c                   | j                  d      }|   }| j                  d      rU| j                  d      j                  d      }|d   |d   cdj                  fd|j                  d      D              }|S )Nr   r1   ~~r  r   c              3  .   K   | ]  }|  y wr  r  )r9  expbe_leftbe_rights     r  r;  z]SQLCompiler._process_parameters_for_postcompile.<locals>.process_expanding.<locals>.<genexpr>v  s       !/ !(h7/s   )r   splitr   )r  r:  exprtokr  r  replacement_expressionss       @@r  process_expandingzJSQLCompiler._process_parameters_for_postcompile.<locals>.process_expandingm  s~    ''!*C*3/D wwqzggaj&&t,$'FCF!yy !#zz$/!  Kr  c                ,    | j                  d         S r  r  r  s    r  r  zASQLCompiler._process_parameters_for_postcompile.<locals>.<lambda>  s    )AGGAJ/r  r  )#rI  r  rb  rK  r4  r  r   rE  r:  r  rP  r  r9  rN  render_literal_bindparamr  rO  $_literal_execute_expanding_parameterliteral_executerw  r  r  r  extendr  r]  r  _post_compile_patternr  r@  r  r.  r/  r  rG  )r  r0  re  expanded_parameterspre_expanded_stringnew_positiontuppre_expanded_positiontupr2  new_processorsto_update_setsnumeric_positiontupnamesebnr  	parameter	to_updater  leep_resreplacement_expr
expand_keyr$  r  r/  r  r:  expanded_stater   r  r  r  r  s                             @@@@@r  r{  z/SQLCompiler._process_parameters_for_postcompile  s   $ ! #77&"&++?? O'+'E'E$'/+/+;+;( :>=O6**
 3Z
  =z
 >@24)+ 48??7C#;E""&(#OO**,E%%D253774.4L

4(ID777'>>55%1;1M 6  ,L9 D444#:: .| <I!F (^^D1F#HH$i H 5=1Y 03<N<0<L+L9 00%%i0 ~~44%111&-- 	.
 5>fa4H	. 	 '-- .*3. 
 +6+22 3093  )4 (...M9.MM8A18A}z1
	1'- !,&&t,S V	 FF&&(9;N
	 *"... !*')>)>!!HC ;;<SEBB!I ..22/I ""#67&
  )<D%-ED*(22DK ?? ^//526 
 1?D-{16s   $M
Mzsqlalchemy.engine.cursorc                    t         j                  j                  }|j                  j	                  | j
                        S )z(utility method used for unit tests only.)r&   	preloadedengine_cursorrc   _create_description_match_mapr  )r  cursors     r  _create_result_mapzSQLCompiler._create_result_map  s5     --**HH  
 	
r  _BindNameForColProtocol_get_bind_name_for_colc                    | j                   }|S r  )r)  )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                  }|j                  D cg c]!  }t        j                  d ||      d       |f# c}d 	|j                  Dj                  j                  | j                   d        |      

| j"                  v r

fd}|	nd |j%                  |j                  D cg c]  }|j&                   c}      	fd}|S c c}w c c}w )Nr  c                4    |j                  |       }||S | S r  r  )	lastrowidr0  param_valueautoinc_keys      r  _autoinc_getterzPSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>._autoinc_getter  s)    ",..i"HK".
  +*  )(r  c                j                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.

            c              3  4   K   | ]  \  }} |        y wr  r  )r9  r+  r  r0  s      r  r;  zWSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get.<locals>.<genexpr>  s     LG[VSfZ0G   c              3  V   K   | ]   \  }}|u r	       n	n |       " y wr  r  )r9  r+  r  autoinc_colautoinc_getterr0  r0  s      r  r;  zWSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get.<locals>.<genexpr>  sL       (/ +-  .9 +9jA!* $J/0 (/   &)r  )r0  r0  r8  r9  getterslastrowid_processorrow_fns   ``r  r  zDSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get  sH     #./	:	 LGLLL  (/  r  )r&   r#  engine_resultr,  r%  r/  r   r  r>   r   primary_keyoperatormethodcaller_autoincrement_columnr  _cached_result_processorr  r9  result_tupler:  )r  resultparam_key_getterr/  r   r  r3  r  r8  r9  r2  r;  r<  r=  s           @@@@@@r  +_inserted_primary_key_from_lastrowid_getterz7SQLCompiler._inserted_primary_key_from_lastrowid_getter  sM    --==!!---&&00	i000 ((
( ""5*:3*?FL(

 11""-"2"2"K"Kd# +;7K djj(
) "1 #'$$9J9J%K9J#cgg9J%KL	 	4 
G
N &Ls   &E E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 t        |      D ci c]  \  }}||
 }}}t        d|j                   D cg c]?  }||v rt#        j$                  ||         dfnt#        j&                  d ||      d       dfA c}      
|j)                  |j                   D cg c]  }|j*                   c}      
fd}	|	S c c}}w c c}w c c}w )Nr1   )rE  z'List[Tuple[Callable[[Any], Any], bool]]Tr  Fc                ,       fdD              S )Nc              3  H   K   | ]  \  }}|r |      n |        y wr  r  )r9  r+  use_rowr0  rows      r  r;  zWSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get.<locals>.<genexpr>3	  s-      '.OFG  'sF:,>>'.r  r  )rL  r0  r;  r=  s   ``r  r  zDSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get2	  s     '.  r  )typingr   enginerE  r&   r#  r>  r%  r/  r  r>   r,  r   r7  r  r   r?  r@  
itemgetterrA  rD  r:  )r  rE  r/  rF  r   r  idxr  retr  r;  r=  s             @@r  +_inserted_primary_key_from_returning_getterz7SQLCompiler._inserted_primary_key_from_returning_getter
	  sk    '^^11F!!---&&00	i000==++	$$$(1)(<=(<HCsCx(<=5 !,, -C cz ((S2D9 !--!#3C#8$ 	 -
" $$9J9J%K9J#cgg9J%KL	 
7 > &Ls   &E
AE
.Ec                     y)zCalled when a SELECT statement has no froms, and no FROM clause is
        to be appended.

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

        r  r  r>  s    r  default_fromzSQLCompiler.default_from:	  s     r  c                    |j                   j                  | fi |}|j                  D ]C  }|| j                  vr| j                  |   }|j	                  |j                  |j
                     dd      }| j                  |   }|x| j                  |<   | j                  |<   || j                  |<   | j                  j                  |d       || j                  v r| xj                  |hz  c_        || j                  v r| xj                  |hz  c_	        | j                  }|s|\  }	}
|j                  D ]4  }|j
                  |
v s|
|j
                     }|	|   j                  |       6 F |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  	translater9  _with_valuer:  r:  r  rO  rN  rQ  _cloned_setr  )r  override_bindsr  sqltextr  bpnew_bpr   r  r  r~  cbs               r  visit_override_bindsz SQLCompiler.visit_override_bindsD	  s`   " <.((;;DGBG  ))A

"AB ^^((0! $ F ??2&D/55DJJqMDJJt,&*DOOF#OOD)T---((VH4(T000++x7+33J'
d..Bvv~!"&&\R/ )? *H r  c                H    d |j                   j                  | fi |z   dz   S Nr&  r'  r  r  )r  groupingasfromr  s       r  visit_groupingzSQLCompiler.visit_grouping	  +    8X%%88HHH3NNr  c                H    d |j                   j                  | fi |z   dz   S ra  rb  )r  rc  r  s      r  visit_select_statement_groupingz+SQLCompiler.visit_select_statement_grouping	  rf  r  c                   | j                   r| j                  j                  r	 t        d| j                   d   d         }|j                  \  }}}|r|}	n|}	|j                  j                  }
|
E|
j                  |	v r7|
j                  |	|
j                           r|j                  j                  |d<    | j                  |j                  fd|i|S # t        $ r}t        j                  d      |d }~ww xY w)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   KeyErrorr2   r  _label_resolve_dictr  _order_by_label_elementr   shares_lineager  )r  r  rm  r  r%  ke	with_cols
only_froms	only_colsresolve_dictorder_by_elems              r  visit_label_referencez!SQLCompiler.visit_label_reference	  s    ::$,,EE	 $=JJrN?3! 11	$)( $OOCCM )!&&,6!00 !3!34
 OO;; ./ t||OO
"7
 
 	
A  &&/ s   C 	C7C22C7c                >   | j                   s| j                  |j                        S 	 t        d| j                   d   d         }j                  \  }}}	 |r||j                     }	n||j                     }	|	|d<    | j                  |	fd|i|S # t        $ r;}t        j                  |j                  dt        j                  |       Y d }~d }~ww xY w# t        $ r;}
t        j                  |j                  dt        j                  |
       Y d }
~
y d }
~
ww xY w)Nrj  r  r%  rk  )extraexc_clsr  rl  rm  )r  r  _text_clauser   ro  r   _no_text_coercionr  r2   r  rp  )r  r  rm  r  r%  rs  rt  ru  rv  r  r  s              r  visit_textual_label_referencez)SQLCompiler.visit_textual_label_reference	  s*    zz<< 4 455	 9

2/M ,9+L+L(	:y	$ 10 /2F*+4<<+@DJ ;  		''/ (( 		"  		''/ (( 		s/   B !C 	C1CC	D!1DDc                H   |xr | }||u }	|	s|rMt        |j                  t        j                        r| j	                  d|j                        }
n|j                  }
|r|1 |
|j                  ||
f|j
                  z   |z   |j                          |j                  j                  | fddd|t        t        j                     z   | j                  j                  |
      z   S |	r| j                  j                  |
      S  |j                  j                  | fddi|S )NcolidentT)rm  within_label_clauserm  F)r  r   r   rC   _truncated_identifierr  r  r  r  	OPERATORSr!   as_r  format_label)r  r  add_to_result_mapr  rm  rl  result_map_targetsr  render_label_with_asrender_label_only	labelnames              r  visit_labelzSQLCompiler.visit_label	  s?    "=*=&= 	 2U: 4%**h&?&?@ 66z5::N	!JJ	 ,!JJI&)9)99<NNJJ	 100*.(, 	 IMM*+ --,,UI>?	 ==--eY??35==33,157 r  c                ,    t        j                  d      )Nz:Cannot compile Column object until its 'name' is assigned.r2   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  c                Z   |j                   x}}|| j                  |      }|j                  }	|	s,t        |t        j
                        r| j                  d|      }|C|||j                  f|z   }
|j                  r|
|j                  fz  }
 ||||
|j                         |	r| j                  |      }n| j                  j                  |      }|j                  }||r|j                  s|S | j                  j                  |      }|r| j                  j!                  |      dz   }nd}t"        rt        |t$              sJ |j                   }|s|r	||v r||   }t        |t        j
                        r| j                  d|      }|| j                  j                  |      z   dz   |z   S )Nr  r)  r  alias)r   r  
is_literalr  r   rC   r  r:  	_tq_labelr  escape_literal_columnr  quoter   named_with_columnschema_for_objectquote_schemar   rZ   )r  r   r  include_tabler  ambiguous_table_name_mapr  r   	orig_namer  targetsr   effective_schemaschema_prefix	tablenames                  r  visit_columnzSQLCompiler.visit_column 
  s    ";;&y<--f5D&&
jx/H/HI--j$?D(tVZZ03EEGF,,..dIwD --d3D==&&t,D=U5L5LK#}}>>uEMM../?@3F  !#!%999

I %,!994Y?	)X%>%>? 66w	J	 4==#6#6y#AACG$NNr  c                L    | j                   j                  |j                        S r  )r  format_collation	collationr  r  r  s      r  visit_collationzSQLCompiler.visit_collation[
  s    }}--g.?.?@@r  c                    |j                   S r  r   )r  
fromclauser  s      r  visit_fromclausezSQLCompiler.visit_fromclause^
  s    r  c                    |j                   S r  r  )r  r~  r  s      r  visit_indexzSQLCompiler.visit_indexa
  s    zzr  c                    ||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_typeclaused
  sJ     *$(MM !:t||22::OO
!
 	
r  c                V    | j                   j                  r|j                  dd      }|S Nr%  %%r  _double_percentsreplacer  texts     r  post_process_textzSQLCompiler.post_process_textk
  $    ==))<<T*Dr  c                V    | j                   j                  r|j                  dd      }|S r  r  r  s     r  r  z!SQLCompiler.escape_literal_columnp
  r  r  c           	           fd} j                   sd _        |r |d d ft        j                         t        j                  d t        j                  | j                  j                                    S )Nc                    | j                  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_bindparamv
  sW    771:Dz---#t||J$:$:4$@GBGG,t,,T8R88r  Tc                $    | j                  d      S r  r  )r  s    r  r  z.SQLCompiler.visit_textclause.<locals>.<lambda>
  s    aggajr  )	r  r8  r%   NULLTYPEBIND_PARAMS_ESCr  BIND_PARAMSr  r  )r  r  r  r  r  s   `` ` r  visit_textclausezSQLCompiler.visit_textclauseu
  sl    	9 zz#D dD:-9J9JK "" OOd44Z__E
 	
r  c                "   | j                    }|r| j                  n| j                   d   }t               t               |d}| j                   j                  |       |j                  r| j                  ||       |xs- |dk(  xr |j                  dd      xs |j                  dd      }|rp|j                  x| _        | _	        |j                   xr t        |j                        | _        |j                  D ]   }	| j                  |	d| j                         "  | j                  |j                  fi |}
| j                   r.|st#        | j                         nd }| j%                  |	      |
z   }
| j                   j'                  d       |
S )
Nr  r!  r   r$   r   r(  Fr'  T)rm  r  nesting_level)r  _default_stack_entryr~   r  _independent_ctes_dispatch_independent_ctesr  rb  rC  rA  r&  column_argsrD  r  _add_to_result_mapr  rU  r  _render_cte_clauser  )r  tafcompound_indexrd  r  toplevelr  	new_entrypopulate_result_mapr  r  r  s               r  visit_textual_selectz SQLCompiler.visit_textual_select
  s{    zz>-5))4::b>  #uE*
	
 	

)$  ++C4  >!# EII<eD>
 yy5u= 	 D!D$A 47>>/A 0dGD, __*.&*&=&=   % t||CKK.2.993;C

OM***G$ND

rr  c                     yNNULLr  r  r	  r  s      r  
visit_nullzSQLCompiler.visit_null
      r  c                2    | j                   j                  ryy)Nr   1r  supports_native_booleanr  s      r  
visit_truezSQLCompiler.visit_true
  s    <<//r  c                2    | j                   j                  ryy)Nr   0r  r  s      r  visit_falsezSQLCompiler.visit_false
  s    <<//r  c                J     |j                  d  fd|D        D              S )Nc              3  $   K   | ]  }|r| 
 y wr  r  r9  ss     r  r;  z7SQLCompiler._generate_delimited_list.<locals>.<genexpr>
  s      
I I   c              3  D   K   | ]  } |j                   fi   y wr  r  r9  r  r  r  s     r  r;  z7SQLCompiler._generate_delimited_list.<locals>.<genexpr>
  s%     I1*a**4626r  r   )r  r   	separatorr  s   `  `r  _generate_delimited_listz$SQLCompiler._generate_delimited_list
  s&    ~~ 
II
 
 	
r  c                t    t         j                  j                  t        j                  t         j
                  j                  t         j                  j                  |      \  }}|dk(  r |d   j                   fi S t        t        j                     }|j                  d  fd|D        D              S )Nr   r   c              3  $   K   | ]  }|r| 
 y wr  r  r  s     r  r;  z;SQLCompiler._generate_delimited_and_list.<locals>.<genexpr>
  s      "LA Lr  c              3  D   K   | ]  } |j                   fi   y wr  r  r  s     r  r;  z;SQLCompiler._generate_delimited_and_list.<locals>.<genexpr>
  s%     LGq.!..t:r:Gr  )r   BooleanClauseList_process_clauses_for_booleanr!   and_rL   
_singletonrI   r  r  r   )r  clausesr  lccr  s   ` `  r  _generate_delimited_and_listz(SQLCompiler._generate_delimited_and_list
  s    11NNNNNN%%OO&&	
W !8071:00<<<!)..1I>> "LG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                    |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
  sG    !!;CJ//0C,t,,Z-?-?KKKr  c                   |j                   }| 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  ro  r2   r  )r  r  r  	operator_dispopstringr  s          r  visit_expression_clauselistz'SQLCompiler.visit_expression_clauselist
  s    ''	**.
 
I444	 +H -1B()0400""H02 	  	L11$	BK	Ls   	A 	A>"A99A>c                d   d}|j                   #| |j                   j                  | fi |dz   z  }|j                  D ]8  \  }}|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  xcondrE  s         r  
visit_casezSQLCompiler.visit_case  s    <<#000@@3FFA"LLLD&)$))$9&9: ,&++D;F;< 	A ) <<#9&,,99$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JrJJr  c                    |j                   j                  | fi |}t        j                  d|      }d |j                  j                  | fi |d|r|j                  d      n|d|r|j                  d      S dS )Nz(.*)( COLLATE .*)zCAST(r   r   r'  r1   r  )r  r  r]  matchr  r   )r  r   r  type_clauser  s        r  
visit_castzSQLCompiler.visit_cast  s    8doo88HH,k:*DKK**4:6:#EKKN4#EKKN+
 	
 *,+
 	
r  c           
     p   |d   t         j                  u rdn|d   t         j                  u rdnh|d   dk  r5 | j                  t        j                  t        |d               fi |dn+ | j                  t        j                  |d         fi |dd|d   t         j                  u rdS |d   t         j                  u rdS |d   dk  r7 | j                  t        j                  t        |d               fi |dS  | 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$:$:: " "!9q=	 )DLL ( 0 0VAY @DF (4<<(8(8(CJrJM( !9 8 88 & +'
 '	
2 ayH$:$:: "+'
 '	
B "!9q=	 )DLL ( 0 0VAY @DF+'
 '	
F (4<<(8(8(CJrJM+'
 '	
r  c                8    |j                   j                  | fi |}|j                  !d | j                  |j                  fi |z  }n\|j                  !d | j                  |j                  fi |z  }n/|j
                  !d | j                  |j
                  fi |z  }nd }|ddj                  d|j                  fd|j                  ffD cg c]*  \  }}|#t        |      r|d |j                  | fi |, c}}|r|gng z         d	S c c}}w )
NzRANGE BETWEEN %szROWS BETWEEN %szGROUPS BETWEEN %sz OVER (r,  	PARTITIONORDERz BY r'  )
r  r  r$  r%  rowsgroupsr   partition_byorder_byr  )r  overr  r  r$  wordr  s          r  
visit_overzSQLCompiler.visit_overQ  s[   .t||..t>v>;;"'*C$*C*C+%+ F YY"&)B)B)B		*#* F [[$(+D4+D+D,%, F F HH
 %d&7&78 $--0))f )c&k 6V66tFvFH)  &F82	/
 	
s   /Dc                ~     |j                   j                  | fi |d |j                  j                  | fi |dS )Nz WITHIN GROUP (ORDER BY r'  )r  r  r,  )r  withingroupr  s      r  visit_withingroupzSQLCompiler.visit_withingroupr  sB    2K224B6B3K  33DCFC
 	
r  c                ~     |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_funcfilterx  s@    .JOO..t>v>3J  33DCFC
 	
r  c                    | j                   j                  |j                  |j                        }d|d |j                  j                  | fi |dS )NzEXTRACT(r   r'  )extract_mapr  fieldr	  r  )r  extractr  r:  s       r  visit_extractzSQLCompiler.visit_extract~  sH      $$W]]GMMB+GLL++D;F;
 	
r  c                r     | 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_column  s?    )d))'**;;(t((7B7'66r  c           	     x   |4 ||j                   |j                   |j                   f|j                         t        | d|j                   j                         z  d       }|r ||fi |}n8t        j                  |j                         j                  d       }|r|j                  ri|dz  }nc|j                   }| j                  j                  |      st        |t        j                        r| j                  j                  |      n|}|dz   }dj                  |j                   D cg c]T  }| j                  j                  |      st        |t        j                        r| j                  j                  |      n|V c}|gz         d | j"                  |fi |iz  }|j$                  r|dz  }|S c c}w )Nzvisit_%s_funcz%(expr)sr)  r	  z WITH ORDINALITY)r   r  getattrlowerr   r  _deannotater  	_has_argsr  _requires_quotes_illegal_charsr  r   r.   r  r   packagenamesfunction_argspec_with_ordinality)r  r4  r  r  r  r  r   r
  s           r  r>  zSQLCompiler.visit_function  s    (diiTYYL$))Lt_tyy/@@$G ''D==!1!1!3!=!=tDD>>J&Dyy }}CCDI!$(<(<= MM''- 	  j(88  $00  1	  ==GGL%dH,@,@A ++C0 !!
  1 &	 ...t>v>?@D   &&Ds   *AF7c                8    | j                  |j                        S r  )visit_sequencesequence)r  
next_valuer  s      r  visit_next_value_funcz!SQLCompiler.visit_next_value_func  s    "":#6#677r  c                F    t        d| j                  j                  z        )Nz2Dialect '%s' does not support sequence increments.r  r  r   r  rN  r  s      r  rM  zSQLCompiler.visit_sequence  s$    !@ll 
 	
r  c                <     |j                   j                  | fi |S r  )clause_exprr  )r  r4  r  s      r  rJ  zSQLCompiler.function_argspec  s     2t224B6BBr  c           
          j                    } |j                  | fi }|r j                  s| _        |j                  }|r j                  n j                   d   }|xs | xr |j                  dd      }	|dk(  r||d<    j                   j                  |d   |d   |||	d       |j                  r j                  |        j                  |j                     }
d	|
z   d	z   j                   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&                  r/|st)         j                         nd } j+                  |d      |z   } j                   j-                  d       |S )Nr  r(  Fr   r)  r!  r   )r!  r   r$   r%  r(  r,  c              3  P   K   | ]  \  }} |j                   f|d   yw))rd  r  Nr  )r9  r  r  rd  r  r  s      r  r;  z4SQLCompiler.visit_compound_select.<locals>.<genexpr>  sC       2DAq %$$!'=C 2s   #&r  rd  Tr  include_following_stackr  )r  _compile_state_factoryr%  r/  r  r  r  r  r  compound_keywordskeywordr   r  selectsgroup_by_clauser  order_by_clause_has_row_limiting_clause_row_limit_clauserU  r  r  r  )r  csrd  r  r  r  r%  compound_stmtr  need_result_mapr\  r  r  s   ` ` `        r  visit_compound_selectz!SQLCompiler.visit_compound_select  s    zz>111"dEfED..!.D%//-5))4::b>" 
 A		8%@ 	 Q "E*

#():#; %n 5 !.0?	
 **++M6B((4g#)) &bjj1	
 #($$$RI4+Hv+H+HII$$$R2622&&*D**2888D993;C

OM''"/,0 (  	  	

rr  c                f    |j                    | j                  |fi |S  | j                  |fi |S r  )_fetch_clausefetch_clauselimit_clause)r  rb  r  s      r  ra  zSQLCompiler._row_limit_clause  s>    '$4$$R2622$4$$R2622r  c                R    d|j                   d||rd|z   nd}t        | |d       S )Nvisit_r$  r  )r  rD  )r  r  
qualifier1
qualifier2attrnames        r  r
  z"SQLCompiler._get_operator_dispatch  s5     *C*2

 tXt,,r  c                "   |||fz  }||d<   ||d<   |j                   ry|j                  rt        j                  d      | j	                  |j                   dd      }|r |||j                   fi |S  | j
                  |t        |j                      fi |S |j                  rX| j	                  |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@  rq  r2   r  r
   _generate_generic_unary_operatorr   _generate_generic_unary_modifier)r  rp  r  r  r  r  s         r  visit_unaryzSQLCompiler.visit_unary  s8    (5(*&7B"#'9B#$>>~~&&2  ..D E5>>8R88<t<<9U^^48:  ^^..D E5>>8R88<t<<9U^^48:  ""> r  c                   | j                   j                  r | 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  r   r   Castr   r  _type_affinityr%   Numericr  r   r@  r  s       r  visit_truediv_binaryz SQLCompiler.visit_truediv_binary9  s    <<''V[[/B/ $,,MM  &||00??'// 0 #LL-- "*!1!1!3 	( V[[/B/$,,v||2r23r  c                   | j                   j                  rn|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 )Nrv  z	FLOOR(%s))	r  rw  r   r  ry  r%   Integerr  r   r{  s       r  visit_floordiv_binaryz!SQLCompiler.visit_floordiv_binaryT  s    LL((!!00H4D4DD V[[/B/$,,v||2r23 V[[/B/$,,v||2r23 r  c                    |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_operatore  sQ    **||334<<6266ldll7??Ab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_operatorn  sV    **||33ldll7??AbAAAldll7??AbAAAr  c                J    d| j                  |t        j                        z  S )Nr  )override_operator)visit_binaryr!   match_opr{  s       r  visit_not_match_op_binaryz%SQLCompiler.visit_not_match_op_binaryw  s,    $++i&8&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_binary|  s3     555Ih'
+-
 
 	
r  c                   |t         j                  u r*t        |      dkD  rddj                  d |D              z  S y|t         j                  u r*t        |      dkD  rddj                  d |D              z  S y| j                  |      S )	Nr   z(%s)) OR (1 = 1r   c              3      K   | ]  }d   ywr  Nr  r9  r  s     r  r;  z6SQLCompiler.visit_empty_set_op_expr.<locals>.<genexpr>       :EfE   zNULL) OR (1 = 1z(%s)) AND (1 != 1c              3      K   | ]  }d   ywr  r  r  s     r  r;  z6SQLCompiler.visit_empty_set_op_expr.<locals>.<genexpr>  r  r  zNULL) AND (1 != 1)r!   	not_in_opr  r   in_opvisit_empty_set_expr)r  r  	expand_opr  s       r  visit_empty_set_op_exprz#SQLCompiler.visit_empty_set_op_expr  s    	+++5zA~(II:E::  ))//)5zA~*II:E::  +,,U33r  c                F    t        d| j                  j                  z        )Nz3Dialect '%s' does not support empty set expression.rR  r  element_typesr  s      r  r  z SQLCompiler.visit_empty_set_expr  s$    !All 
 	
r  c                   	
 j                   j                   j                        }|s|j                  rO j                  j                  rdnd j                  j                   j                  j                        z   }d|fS  j                  j                   gj                        }d|fS |j                  sB|j                  rt        |d   t        j                        rst        |d   t        t        f      sZ|j                  rt        d       j                  j                  rdnddj!                   fdt#        |      D              z   }d|fS |r j$                  }|j'                  |      }|r|j)                  d      sJ d       |j)                  d      j+                  d	      }|d
   |d   c	
dj!                  	
 fd|D              }d|fS dj!                   fd|D              }d|fS )NVALUES r  r   z?bind_expression() on TupleType not supported with literal_bindsr   c           	   3     K   | ]B  \  }}d dj                  fdt        |j                  j                        D              z   D yw)r   r   c              3  H   K   | ]  \  }}j                  ||        y wr  r  )r9  r  
param_typer  s      r  r;  z[SQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>.<genexpr>  s/      2-E: 11%D2r  N)r   r  r  r  )r9  r  r  r  r  s      r  r;  zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>  sT       ):$A} II 14)9>>+?+?2  ):s   AAr1   )unexpected format for expanding parameterr  r   r  c              3  b   K   | ]&  }j                  |j                         ( y wr  r  r  )r9  r  r  r  r  r  s     r  r;  zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>  s9      3 "(	  11%H 	 "(s   ,/c              3  V   K   | ]   }j                  |j                         " y wr  r  )r9  r  r  r  s     r  r;  zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>  s*      3!' --eY^^D!'r:  r  )r  r  r  r  tuple_in_valuesr  r  r  _isnullr  collections_abcr   r   bytes_has_bind_expressionr  r   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
  ..!%!=!=I200NN(()*=*=*&z )))m *.)E)E^^$i&9&9*&l )))e ,,$$6!9o&>&>?vay3,744)$  "\\99	r		  )2&(9 &"N )))1 ('+'A'A$(//0HIQWW ?>?  ggaj&&t,$'FCF!)- 3 "(3 *& ))) *. 3!'3 *&
 )))r  c                p   
 j                   r j                  |      S  j                  }j                  j	                  |       j
                  r j                  n j                   j                  j                  rj                  r	 fd
nfd
|smg j                  r4 j                  j                  j                  j                        }|fS  j                  j                  gj                        }|fS j                  sBj                  rt        |d   t         j"                        rt        |d   t$        t&        f      sj(                  rJ t+        |d      D 	cg c]%  \  }}t+        |d      D ]  \  }}	|d|d||	f ' c}	}}}|j,                  rdnddj/                  
fd	t+        |      D              z   }|fS t+        |d      D 	cg c]  \  }}	|d||	f c}	}dj/                  
fd
D              }|fS c c}	}}}w c c}	}w )Nc                H    j                  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,    ,,NN$!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   r   r$  r  r  r   c              3  z   K   | ]0  \  d dj                  fdt              D              z   2 yw)r   r   c              3  ^   K   | ]$  \  }} t              z  |z      d           & yw)r   N)r  )r9  r  r  r  r  r  r  s      r  r;  zMSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>.<genexpr>!  sD       )AHAu -%a#m*<&<q&@A!D )As   *-N)r   r  )r9  r  r  r  r  s    @@r  r;  zCSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>  sG       ):$A} II  )2-(@	  ):s   6;c              3  4   K   | ]  \  }} |        y wr  r  )r9  r:  r  r  s      r  r;  zCSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>/  s      /<Ejc5$S)Ir6  )r  r  r  r  r  rE  r?  r>  _bind_typing_render_castsr  r  r  r  r  r  r  r  r   r   r  	_is_arrayr  r  r   )r  r   r  r  r  r  r  r  r  r  r  r  r  r  s   ` `       @@@@r  r  z0SQLCompiler._literal_execute_expanding_parameter  sO   $$JJ6  ,,$>>AA'J 99M --M LL22 11 6 I..)-)E)ENN(()*=*=*&V 000O *.)E)E^^$i&9&9*&N 000G ,,$$6!9o&>&>?vay3,7'1111 )2&!(<(<$A} )- ;HAu  $Q*E2 ; 3(<I %44	"		  )2&(9 &". 000 !*&! 4 4HAu !!$e, 4I &*YY /<E/ &" 000;*s   =*H*
5H2c           	        |rt        j                  |j                        r|w|d   }|j                  j	                  t        j                  t        |j                  j                  |gz         t        |j                  j                  |gz                      ni|j                  j	                  t        j                  t        |j                  j                        t        |j                  j                                     | j                  rMt        |j                  t        j                        r)t        |j                  t        j                        rd|d<   |xs |j                  }| 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@  r  rw  r  productr)   r   r*   r   r=  r  r   rE   r
  r  r  ro  r2   r  )r  r   r  eager_groupingr  r  r  r  r  r  r  r  s               r  r  zSQLCompiler.visit_binary5  s    9226??C".$&':$;!#))00%%!"KK559J8KK ""LL66:K9LL		 !!((%%!&++";";<!&,,"<"<=   6;;(>(>?6<<)?)?@$(B !%8	**9hE	0R00$Y/ 5t44 !,(;	
    P55dIFCOPs   	F. .	G7GGc                <     | j                   |j                  fi |S r  )r  sql_functionr  s       r  &visit_function_as_comparison_op_binaryz2SQLCompiler.visit_function_as_comparison_op_binarym  s    t||G007B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  r   r   r{  s       r  visit_mod_binaryzSQLCompiler.visit_mod_binaryp  s    ==))V[[/B/$,,v||2r23 V[[/B/$,,v||2r23r  c                    |j                   |d<    | j                  |d| j                  |j                        z   dz   fi |S )Nr  r,  )r  r  r  r  r  s       r  visit_custom_op_binaryz"SQLCompiler.visit_custom_op_binary~  sS    '66,t,,$,,X->->??#E
 
 	
r  c                b     | j                   || j                  |j                        dz   fi |S r  )rr  r  r  r  s       r  visit_custom_op_unary_operatorz*SQLCompiler.visit_custom_op_unary_operator  s:    4t44T//0A0ABSH
LN
 	
r  c                b     | j                   |d| j                  |j                        z   fi |S r  )rs  r  r  r  s       r  visit_custom_op_unary_modifierz*SQLCompiler.visit_custom_op_unary_modifier  s:    4t44S455h6G6GHH
LN
 	
r  c                    |j                  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@  r   r  r   )r  r   r  r  r  r	  r  s          r  r  z$SQLCompiler._generate_generic_binary  s     #%&&)BE"J(,$%!??<*FKK**%379  .fll--%379	 	 #~D=Dr  c                B    | |j                   j                  | fi |z   S r  rb  r  rp  r  r  s       r  rr  z,SQLCompiler._generate_generic_unary_operator  s$    :%--::4F2FFFr  c                B     |j                   j                  | fi ||z   S r  rb  r  s       r  rs  z,SQLCompiler._generate_generic_unary_modifier  s#    /u}}//;;hFFr  c                L    t        j                  dt        j                        S )Nz'%')r  )r   literal_columnr%   
STRINGTYPEr>  s    r  _like_percent_literalz!SQLCompiler._like_percent_literal  s    &&uH4G4GHHr  c                D    d |j                   j                  | fi | dS )Nzlower(r'  rb  r  s      r  $visit_ilike_case_insensitive_operandz0SQLCompiler.visit_ilike_case_insensitive_operand  s)    :::4F2FGqIIr  c                    |j                         }| j                  }|j                  |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  sQ    ,,~~fll3::7C(t((@R@@r  c                    |j                         }| j                  }|j                  |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  sQ    ,,~~fll3::7C,t,,VXDDDr  c                   |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              j	                  |      |_         | j                  ||fi |S r  r  r  r  r   r  r   visit_ilike_op_binaryr  s        r  visit_icontains_op_binaryz%SQLCompiler.visit_icontains_op_binary  sl    ,,,V[[9~~"6<<0

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

&/ 	 .t--fhE"EEr  c                    |j                         }| j                  }|j                  |j                        |_         | j                  ||fi |S r  )r  r  _rconcatr   r  r  s        r  visit_startswith_op_binaryz&SQLCompiler.visit_startswith_op_binary  sH    ,,''5(t((@R@@r  c                    |j                         }| j                  }|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  sH    ,,''5,t,,VXDDDr  c                    |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              |_         | j                  ||fi |S r  )r  r  r  r   r  r   r  r  s        r  visit_istartswith_op_binaryz'SQLCompiler.visit_istartswith_op_binary  s^    ,,,V[[9''(>v||(LM)t))&(AbAAr  c                    |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              |_         | j                  ||fi |S r  )r  r  r  r   r  r   r  r  s        r  visit_not_istartswith_op_binaryz+SQLCompiler.visit_not_istartswith_op_binary  s^    ,,,V[[9''(>v||(LM-t--fhE"EEr  c                    |j                         }| j                  }|j                  |j                        |_         | j                  ||fi |S r  r  r  s        r  visit_endswith_op_binaryz$SQLCompiler.visit_endswith_op_binary  sF    ,,~~fll3(t((@R@@r  c                    |j                         }| j                  }|j                  |j                        |_         | j                  ||fi |S r  r  r  s        r  visit_not_endswith_op_binaryz(SQLCompiler.visit_not_endswith_op_binary  sF    ,,~~fll3,t,,VXDDDr  c                    |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              |_         | j                  ||fi |S r  r  r  s        r  visit_iendswith_op_binaryz%SQLCompiler.visit_iendswith_op_binary  s\    ,,,V[[9~~&<V\\&JK)t))&(AbAAr  c                    |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              |_         | j                  ||fi |S r  r  r  s        r  visit_not_iendswith_op_binaryz)SQLCompiler.visit_not_iendswith_op_binary  s\    ,,,V[[9~~&<V\\&JK-t--fhE"EEr  c                   |j                   j                  dd       } |j                  j                  | fi |d |j                  j                  | fi ||%d| j                  |t        j                        z   z   S dz   S )Nr^  z LIKE  ESCAPE r  	modifiersr  r   r  r   r  r%   r  r  r   r@  r  r^  s        r  r  z SQLCompiler.visit_like_op_binary  s    !!%%h5 +FKK**4626+FLL++D7B7

 ! 2268;N;NOO	
 	
 
 	
r  c                   |j                   j                  dd       } |j                  j                  | fi |d |j                  j                  | fi ||%d| j                  |t        j                        z   z   S dz   S )Nr^  z
 NOT LIKE r  r  r  r  s        r  r  z$SQLCompiler.visit_not_like_op_binary  s    !!%%h5*FKK**4626+FLL++D7B7

 ! 2268;N;NOO	
 	
 
 	
r  c                    |t         j                  u rD|j                         }t        |j                        |_        t        |j
                        |_         | j                  ||fi |S r  )r!   ilike_opr  r  r   r   r  r{  s       r  r  z!SQLCompiler.visit_ilike_op_binary  sW    y)))]]_F0=FK1&,,?FL )t((@R@@r  c                    |t         j                  u rD|j                         }t        |j                        |_        t        |j
                        |_         | j                  ||fi |S r  )r!   not_ilike_opr  r  r   r   r  r{  s       r  r  z%SQLCompiler.visit_not_ilike_op_binary(  sW    y---]]_F0=FK1&,,?FL -t,,VXDDDr  c                j    |j                   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_binary1  sA    $$((e<	,t,,Y)K
KM
 	
r  c                j    |j                   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_binary7  sD    $$((e<	,t,,)2%
 
 	
r  c                Z    t        j                  d| j                  j                  z        Nz/%s dialect does not support regular expressionsr2   r  r  r   r{  s       r  visit_regexp_match_op_binaryz(SQLCompiler.visit_regexp_match_op_binary?  ,     =ll 
 	
r  c                Z    t        j                  d| j                  j                  z        r  r  r{  s       r   visit_not_regexp_match_op_binaryz,SQLCompiler.visit_not_regexp_match_op_binaryG  r  r  c                Z    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_binaryO  s,     Ill 
 	
r  c           	     ^   |s|j                   j                  | j                        }|j                  r|j	                  |      }	 | j
                  |	fd||xr |j                   ||d|}
|j                  rut        j                  d|
      }|sJ d       d|j                  d      d|j                  d      d	|j                  d
      d}
|r | j                  |fd|
d|}d|z  S |
S |s3|xs |j                  xs |xr | j                  }|xs |j                  }nd}|r( | j                  |fddi|}|j                  rd|z  }|S | j                  |      }|| j                  v r5| j                  |   }||ur!|j                  s|j                  rb|j                   j#                  |j                         s=|j$                  j#                  |j$                        st'        j(                  d|z        |j                  |j                  k7  rt'        j(                  d|d      |j*                  s|j*                  r]|j*                  r!|j*                  rt'        j(                  d      t'        j(                  d|j,                   d|j,                   d      |x| j                  |j,                  <   | j                  |<   | j.                  }|rH|\  }}|j$                  D ]4  }|j,                  |v s||j,                     }||   j1                  |       6 |j2                  rd| _        |r8|rd| _        |r| xj8                  |hz  c_        n| xj:                  |hz  c_         | j<                  |f||j                  |j                   d|}|j                  rd|z  }|S )NT)skip_bind_expressionrm  literal_bindsr  render_postcompilez&^(.*)\(__\[POSTCOMPILE_(\S+?)\]\)(.*)$r  z(__[POSTCOMPILE_r1   r  r   z~~REPL~~r  z~~]))rm  r  r   Frm  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  r  r]  r  r   r  r  r=  _truncate_bindparamr9  r   r	  intersectionrY  r2   r  _is_crudr:  rQ  r  
isoutparamhas_out_parametersrF  rN  rO  r  )r  r  rm  r  r  r  r  r  implr"  wrappedr  rQ  r  r   existingr  r  r~  r\  r^  s                        r  visit_bindparamzSQLCompiler.visit_bindparamW  s    $>>..t||<D(("&"6"6y"A&$,,#)-*?"/"K	8K8K4K$3'9  && A7A III1


G %;d;;%265< %	  &|+ D,,D)Bd.B.B 
 +Ai.A.AL L/$//159?C ""slJ''	24::zz$'Hy(__	(8(8$..;;!++ %00==!-- **ACGH  ''9+>+>>** :>@  &&)*<*<((Y-?-? "..&
 
 "..0 @" #,--5	 	 8A@

9==!DJJt$4 //
#JD$++66T>bffBHOOI. ,
 &*D#!+/(++	{:+((YK7(#d##
%))$>>	

 
 3,C
r  c                    t               r  r  )r  r  
dbapi_typer[  s       r  r  zSQLCompiler.render_bind_cast  s    !##r  c                   |t         ur|}n|j                  |j                  x|j                  dd       }|rC|t        j
                  t        j                  fvr!t        j                  d|j                  f        | j                  t        j                  fi |S |j                  }|j                  r| j                  } ||||      \  }}	|	S | j!                  ||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_limitedr:  r  r%   r  r  r  r  r  r  )
r  r  r  r  r  r  opleepr  r  s
             r  r  z$SQLCompiler.render_literal_bindparam  s      v-(E&9+=+=+EVVL$/"Y]]I4D4D$EE%%@ #(	 $t||H$5$5<<<--EJJD*.)A+'I'
 $#,,UINNCCr  c                   |9|j                   s-| j                  t        j                  j	                               S |j                  | j                        }|r		  ||      S t        j                  dt        j                  |       d|       # t        $ r5}t        j                  dt        j                  |       d| d      |d}~ww xY w)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   rK   	_instance_cached_literal_processorr  r  r2   r  sql_util_repr_single_value)r  r  r  	processores        r  r  z SQLCompiler.render_literal_value   s     =!;!; << 7 7 9::33DLLA		 '' ""//67 8!!&)   && 33E:; <%g ## s   B 	C0C		Cc                    || j                   v r| j                   |   S |j                  }t        |t        j                        r| j                  d|      }|| j                   |<   |S )Nr  )r:  r:  r  r   rC   r  )r  r  r  s      r  r#  zSQLCompiler._truncate_bindparamG  s^    '??9--MM	i!:!:;22;	JI &/	"r  c                   ||f| j                   v r| j                   ||f   S |j                  | j                        }t        |      | j                  dz
  kD  r]| j
                  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$  r1   )	rq  	apply_maprp  r  rn  rr  r  maxhex)r  ident_classr   anonnamecounter	truncnames         r  r  z!SQLCompiler._truncated_identifierT  s     $"6"66''d(;<<>>$--0x=4,,q00..22;BGS!2!2Q!6:;g,qr"# 
 5<aKD$$[1 I4=k401r  c                     || j                   z  S r  rp  r  r   s     r  
_anonymizezSQLCompiler._anonymizei  s    dmm##r  c                    ||j                  |       ||j                  |       |s> j                  j                  |      r# j                  j	                   fd|      }	|}|	}|r" j
                  j                  ||i       _        |rGd|z  }
|r|
S |:|j                   j                        }|j                  r j                  |||
      }
|
S  j                  t        j                  u r j                  d|iz  }
n j                  d|iz  }
|P j                  j                   r:|j                   j                        }|j                  r j                  |||
      }
|
S )Nc                @    j                   | j                  d         S )Nr   )r/  r   )r  r  s    r  r  z.SQLCompiler.bindparam_string.<locals>.<lambda>  s    d88Dr  z__[POSTCOMPILE_%s]r   )addr  r.  r  r  rP  r   r  r  render_literal_castr  r  ro  rp  r?  r>  r  )r  r   r  r  escaped_fromr   accumulate_bind_namesvisited_bindparamr  new_namerQ  	type_impls   `           r  r  zSQLCompiler.bindparam_stringl  ss    !,!%%d+($$T*&&--d3  2266D  $&*&=&=&C&Ct$'D# &-C 
 )*BBLL	 00//	3OCJZZ=222//64.@C##vtn4C &66&>>t||LI))++NIsK
r  c                    |j                         }|j                  dd        t        |j                  |j                        D ]  \  }} |j
                  | fd|i|  y )Ncte_opts)copyr  r  r  _independent_ctes_optsr  )r  stmtr  local_kwcteopts         r  r  z&SQLCompiler._dispatch_independent_ctes  s[    779Z&""D$?$?
HC #C""4B#BB
r  c                "
     j                         }	|	 j                  u sJ ||d<   |j                  }
t        |
t        j
                        r j                  d|
      }
d}d}|j                         }|j                  xs |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                  |<   n=|rt         j                        nd}||
f}| j                  v r j                  |   }nd }|||u }||j                  u s||u rd}n||j                  u r-|	|= |j                         }||u sJ ||u sJ  j                  |= n[t!        |      t!        |      k(  s)|j"                  |j"                  |j%                  |      rd}nt        j                  d|
z        |s|sy |j&                  O|j&                  }|j&                  j                  }t        |t        j
                        r j                  d|      }n|}d }|r| j                  |<   ||fz    j                  |<   | j                  vr  j(                  |fi | |s]||	vrX|j*                  rd _         j.                  j1                  ||
      }|j*                  r^|j2                  }|j5                  d      D cg c]  \  }}}}}|s|xs | }}}}}}|dd	j7                   fd
|D              z  z  }|j9                  dd      du sJ  j                  s |j2                  j:                   fd|i|S   j<                  ||j>                  fi |}  |j2                  j:                   fddi|}!|d| d|!dz  }|j@                  r$|d  j<                  ||j@                  fi |z   z  }||	|<   |r|r|
|jB                  |jE                         <   |s|r j.                  j1                  ||
      S |rh j.                  j1                  ||      } j.                  jG                  |
      r j.                  jI                  |
      }
| jK                  |
      z  }|S  j.                  j1                  ||
      S y c c}}}}}w )Nvisiting_cter  TFz6CTE is stated as 'nest_here' in more than one locationr   z5Multiple, unrelated CTEs found with the same name: %rr   r   c              3  l   K   | ]+  }j                   j                  |j                          - yw)rG  N)r  format_label_namerp  )r9  identr  s     r  r;  z(SQLCompiler.visit_cte.<locals>.<genexpr>[  s:      " *4 !MM;; % <  *4s   14subqueryrd  r   z
(r'  r,  )&r  rU  r   r  r   rC   r  _get_reference_ctenestingrW  rV  r2   r  r  r  	_restateshash_is_clone_ofcompare
_cte_alias	visit_cte	recursiverX  r  format_aliasr  _generate_columns_plus_namesr   r  r  _generate_prefixes	_prefixes	_suffixesr  r)   _requires_quotesr  get_render_as_alias_suffix)"r  rY  rd  ashint	fromhintsr\  r  rT  r  	self_ctescte_name
is_new_cteembedded_in_current_named_cte_reference_cterb  	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
proxy_namefallback_label_namer  repeated
recur_colsprefixesr   s"   `                                 r  rh  zSQLCompiler.visit_cte  s    ((*	DII%%%!$~88h 9 9:11'8DH
(-%//1++1!1!1 T333.2.D.D/+Iq+ = ='2N22>BL
 $,,**1 
 #,X!6/6C

OA	3<h2GG++N;:F''79GK :&&~6
 ,3DJJI'2N!8!88#66~F##,8L,H) l,,,|0C"
. l+-9-L-L-N*1^CCC1\AAA**+EF
 #Y$|"44  ,,8+88D  KK5 "'J
 **,.67 
 j>>%NNM!$!4!4,h.G.GH%)%?%?/&"  M!%69D##N35CG 6D"">2 DII-}77%#Y*>==*.D'}}11#x@==!$J" )EEdK" L&/$' ,9z9 L  "  F		 " *4	"  D zz*e4===zz :3;;99%+/5   7t66S]] .4 H ;CKK::%)-3E h>>D==C"9$"9"9S]]#.4#  D "&	#5=!!#--/2"?}}11#x@@!}}11#7IJ==11(;#}}228<H77AA}}11#x@@G"s   T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  sN    ## $B}%4%%g444#4##G2r22r  c                (     | j                   |fi |S r  )r  r  s      r  visit_table_valued_columnz%SQLCompiler.visit_table_valued_column  s     t  /B//r  c
           
        
 |r&d
vrj                   sJ 
d<   |	rd
vr	d
v r|	
d<   |@|j                  u r2 j                  j                   f|||||d
}|r
|s|rd|d}|S x}
d<   |s|rMt        j                  t
        j                        r j                  dj                        }nj                  }|r j                  j                        S |r|	r|	j                  j                         <    j                  j                   fd|d	
}|rd|d}| j                   j                  j                              z   }j                  r8j                  r,|d
dj                  
 fdj                   D              z  z  }|r|v r j#                  ||   |      }|S  j                  j                   fd|i
S )Nr  r  )rd  rq  iscrudrr  lateralenclosing_aliasr&  r'  r  r  T)rd  r  r   r   c              3     K   | ]m  }j                   j                  |j                        j                  r4d  j                  j
                  j                  |j                  fi z  nd o yw) %sr  N)r  r  r   _render_derived_w_typesr  r  r  r  )r9  r  r  r  r  s     r  r;  z*SQLCompiler.visit_alias.<locals>.<genexpr>  s}       $+C !MM//9 $)#@#@	 !&"M$,,"E"E"M"M$'HH#"06#"!"
 &(!(	 $+s   A3A6r  )r  r  r  r  r   r   rC   r  r  rj  r  r)   rp  _supports_derived_columns_render_derivedr   r  format_from_hint_text)r  r  rd  rq  r  rr  r`  r  r  r  r  r   
alias_namerQ  s   ``        `   r  r  zSQLCompiler.visit_alias  s4    "&0 ((((.3*+
 )7'610;,-&?+B+Be+K4EMM44	# %	 	E Vw"')L:??Of%67V%**h&?&?@!77L
"ZZ
==--eZ@@7A!!%//"344EMM44!76<E "')$99**5*= C ..53H3HvII  $)77  $ Ui/00	% 0& J 45==33%)/ r  c                2    d|d<    | j                   |fi |S )NTr`  r  )r  r`  r  s      r  visit_subqueryzSQLCompiler.visit_subquery  s#    :t/B//r  c                8    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                         j                  | fi |}|j                  #|d |j                  j                  | fi |z  z  }|S )Nrd  Tz TABLESAMPLE z REPEATABLE (%s))r  _get_methodr  seed)r  tablesamplerd  r  r  s        r  visit_tablesamplezSQLCompiler.visit_tablesample  s    D[<<<8K##%88DD

 '&3  33D?B? D r  c                     j                  dj                         dj                   fdj                  D              }d| S )Nr  r   c           	   3     K   | ]I  }|D ]B  } j                   t        j                  |d j                  ij	                         fi  D K yw)r  N)r  r   r   _column_typesr  )r9  chunkelemr  r  r  s      r  r;  z-SQLCompiler._render_values.<locals>.<genexpr>  se      	
 ' DLL26!//*, 	  '   AAr  )
setdefaultr  r   _data)r  r  r  tupless   ``` r  _render_valueszSQLCompiler._render_values  sG    
ow'<'<= 	
 !	
 	
 !!r  c           
     (      j                   |fi }|j                  rd }nMt        |j                  t        j
                        r j                  d|j                        }n|j                  }|j                  rd}nd}|r|r!||nd|j                  |j                         <   |r`dd<   |d|d j                   j                  j                  |            d	d
j                   fd|j                  D              d}|S |d|d}|S )Nr  zLATERAL r  z(unnamed VALUES element)Fr  r&  r'   (r   c              3  D   K   | ]  } |j                   fi   y wr  r  r  s     r  r;  z+SQLCompiler.visit_values.<locals>.<genexpr>=  s+      "%4 1A00<<%4r  )r  _unnamedr  r   r   rC   r  r  r  r)   rp  r  r  r   columns)r  r  rd  r  r  r  r   r  s   `   `   r  visit_valueszSQLCompiler.visit_values!  s   D.2.Dh&?&?@--hED<<D GG ,D2L !!'"3"3"56 &+?#33DMM4G4G4MN		 "%,__" 
  !(+r  c                0    d | j                   |fi | dS ra  )r  r  s      r  visit_scalar_valueszSQLCompiler.visit_scalar_valuesG  s%    &4&&w5"56a88r  c                    d|z   S )Nr   r  )r  alias_name_texts     r  rp  z&SQLCompiler.get_render_as_alias_suffixJ  s    ''r  c                    |sJ ||dk(  rd| _         d| _        |j                  rt        j                  d      | j
                  j                  t        ||||             y )N*FTzxMost backends don't support SELECTing from a tuple() object.  If this is an ORM query, consider using the Bundle object.)rC  rB  r  r2   r  r  r  r   r  s        r  r  zSQLCompiler._add_to_result_mapM  sk     w?gn$)D!#'D ""4 
 	##wgu=	
r  c                8     | 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  rW  r   r  column_clause_argsr  s         r  _label_returning_columnz#SQLCompiler._label_returning_columnf  s:     )t(($,B2D
 
 	
r  c                <   j                   j                  | j                        }|j                  r|s|r|j	                        }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      }n8|}n4|r%|J d       t        |||j                  f      }n|urd}nt        t        j                        r"|xr j                   xr j                  du}nst        t        j                         rd}nVt        t        j"                        rj$                  xs |}n+t        t        j&                        sj(                  d}nd}|rS|s|
rJ j*                  }t        |t        j,                        st        j,                  |      n|}t        |||f      }n|}|j/                  |	||	        |j0                  | fi |S )
z.produce labeled columns present in a select().c                     | || f|       y r  r  )r   r   r  r  r  s       r  r  z;SQLCompiler._label_select_column.<locals>.add_to_result_map  s    &wwj%Hr  c                $     | |f|z   |       y r  r  )r   r   r  r  r  r   s       r  r  z;SQLCompiler._label_select_column.<locals>.add_to_result_map  s    &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)rm  r  r  )r  r!  r  _has_column_expressioncolumn_expressionr  r  r   rJ   r   r   r  r  rG   r  r   
TextClauseUnaryExpressionwraps_column_expressionNamedColumn_non_anon_label_anon_name_labelrC   rw  r  )r  r   r   r  rd  r  r   r  r  rm  column_is_repeatedneed_column_expressionsr  r(  col_exprr  result_exprrender_with_labelr  s     `               @r  r  z SQLCompiler._label_select_column{  sf     {{''5&&#':--f5HH
 !% 7 7
 "%6"I
 '%6" !% % 	
:	
$ fhnn-v%+fkkfnn5F ' &<;<& ( $$K& v% %)!FH$9$9:  1"---1D0 "
 FH$7$78$)!FH$<$<=$*$B$B$Lf!
 vx';';< **2$(!$)! *
  211*0*A*A' &+X-F-F --.AB - $ ,1j] '!!"7/' 	" 	

 .{--dI6HIIr  c                >    | j                  ||      }|r|d|z   z  }|S r  )get_from_hint_text)r  r[  r   hintr  hinttexts         r  r  z!SQLCompiler.format_from_hint_text  s*    **5$7sX~%Gr  c                     y r  r  )r  byfromss     r  get_select_hint_textz SQLCompiler.get_select_hint_text%      r  c                     y r  r  r  r   r  s      r  r  zSQLCompiler.get_from_hint_text(  s     r  c                     y r  r  r  s      r  get_crud_hint_textzSQLCompiler.get_crud_hint_text-  r  r  c                $    dj                  |      S r  r  )r  
hint_textss     r  get_statement_hint_textz#SQLCompiler.get_statement_hint_text0  s    xx
##r  r$  r  r!  r   c                   | j                    }|r| j                  n| j                   d   }|j                  ||       }|d   }|d   }	|r&|s$|j                  |j	                  |	      d      }
|
S |j                  ||	      }
|
S )Nr  r!  r   r  explicit_correlate_fromsimplicit_correlate_froms)r  r  rZ  _get_display_froms
difference)r  select_stmtrd  r  r  r  r  r%  r!  r   r  s              r  _display_froms_for_selectz%SQLCompiler._display_froms_for_select:  s     zz>-5))4::b>#::;M 12^,'!44)8)C)C * *,	 5 E 	 "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xs |}| j
                  r? | j
                  |fd|i|	}||ur&|
}|}|} |j                   || fi |	}
|
j                  }|r| j                  n| j                  d   }|xs& |j                  dd      xs |j                  dd      x}}|rd}|sd	|	v r|	d	= | j                  ||
||||      }|	j                         }|j                  ddd
       d}|j                  r| j                  |      \  }}|r||dz   z  }nd }|j                  r| j                  ||	       |j                  r!| | j                   ||j                  fi |	z  }| | j"                  |fi |	z  }|
j$                  D cg c]#  \  }}}}}| j'                  ||||||||||
      % c}}}}}D cg c]  }|| }}|r|t)        t+        |
j$                  D cg c]
  \  }}}}}| c}}}}}j$                  D cg c]
  \  }}}}}| c}}}}}            %| j,                  D  cg c]'  \  }}}} t/        ||t1        %fd|D              |       ) c} }}}| _        | j3                  |||
|||||	      }|j4                  rQ|j4                  D !"cg c]!  \  }!}"|!d| j6                  j8                  fv r|"# }#}!}"|#r|d| j;                  |#      z   z  }| j<                  r2|r|r.|st?        | j                        nd }$| jA                  |$      |z   }|jB                  r$|d | j                   ||jB                  fi |	z   z  }| j                  jE                  d       |S c c}}}}}w c c}w c c}}}}}w c c}}}}}w c c} }}}w c c}"}!w )NzpSQLAlchemy 1.4 requires use of the translate_select_structure hook for structural translations of SELECT objectsFrm  r  rd  r  r(  r'  r  )r  rm  zSELECT r,  )r   r  r  r  r  c              3  B   K   | ]  }j                  ||        y wr  r/  )r9  orW  s     r  r;  z+SQLCompiler.visit_select.<locals>.<genexpr>  s     $F#QY]]1a%8#s   r  r  )#rZ  _ambiguous_table_name_mapr/  r  r%  r  r  r  _setup_select_stackrU  rw  _hints_setup_select_hintsr  r  rm  rl  get_select_precolumnscolumns_plus_namesr  r  r  r  r   r=  _compose_select_body_statement_hintsr  r   r  rU  r  r  rn  r  )&r  r  rd  insert_intorr  r  select_wraps_forr  r  r  r%  r  is_embedded_selectnew_select_stmtcompile_state_wraps_forr  r  r  r  r  r  	hint_textbyfromr   r  r  r   r  r  inner_columnsr:  r  r  dialect_namehtper_dialectr  rW  s&                                        @r  visit_selectzSQLCompiler.visit_select^  s      ' 	
-	
' +0&':::
!'
 33 	)* $--zz>D..!.D+47F;
 **=d==$*.4O k1*7'#. - B B B!)/! ,55-5))4::b>  >yy7?>yy5u=	
5 "'
 #':f'D*+((vw
 $[[]!!$)EJ	
  $ 8 8 EIv	C'F((++K@  +D++[226< D 	***;A&AA. #55'& 6'# ))'&)(;'/,C * $ 6'
* }-  	 
4 #3#?  +==	 >&/ $  >	$ 5GG	 H&/ $  H	I: .2-A-A	$ .B)CsE #u$F#$FF .B	$D  ((	
 '' +6*F*F*F&\2C):):#;; *F  
 d::;GGG 990H3;C

OM***G$ND  C1$11[226<  D 	

ry
@		$&s$   &(OOO+O(,O1
&O9c                    |j                   j                         D ci c];  \  \  }}}|d| j                  j                  fv r||d|j	                  | d      iz  = }}}}| j                  |      }||fS c c}}}w )Nr  r   T)rq  )r  rx  r  r   r  r  )r  r   r  r  r  r  r  s          r  r  zSQLCompiler._setup_select_hints+  s     /5mm.A.A.C
 /D* (3 1 122 8u//T/BCD D.C 	 
 --f5	&  
s   A A8c           	        |d   }|d   }|dk(  r||d<   nf|rd|d   }	t        |	j                        }
t        |j                        |
k7  r2t        j                  dd|
|dz   t        |j                        fz        |r%|s#|j                  |j                  |      d      }n|j                  ||      }t        t        |       }|j                  |      }||||d	}| j                  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  r2   r  r  r  r~   r*   r   r  r  )r  r   r%  r  rd  r  r  r!  r   r)  numcolsr  new_correlate_fromsall_correlate_fromsr  s                  r  r  zSQLCompiler._setup_select_stack7  s;      12^,Q &E*Z(H(889G=334?&&!
 &*F889			  '!44)8)C)C * *,	 5 E "44)8)5 5 E
 "-"78177H 02 *	*
	 	

)$r  c	                ,   |dj                  |      z  }| j                  t        z  r1t        i t	                     }	| j                  t
        z  }
|r|	| _        nd }	d}
|s|j                         }|r|dz  }|j                  r8|dj                  |D cg c]  } |j                  | fd||	d| c}      z  }nJ|dj                  |D cg c]  } |j                  | fd|	d| c}      z  }n|| j                         z  }|j                  r) | j                  |j                  fd|	i|}|r|d|z   z  }|
r|	J |	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 c c}w c c}w )
Nr   Fz 
FROM T)rd  rr  r  rd  r  r  z 
WHERE z	 
HAVING )r   rh  rv  rz  r~   rw  r  rstripr  r  rT  _where_criteriar  r  _group_by_clausesr^  _having_criteria_order_by_clausesr_  r`  ra  _for_update_argfor_update_clause)r  r  r   r%  r  r  r  r  r  r  warn_lintingfts                r  r  z SQLCompiler._compose_select_bodyk  s    			-((<<44$R/K<<,6L#. K L ;;=DJD}}		 "'	 "'A -,, #'&,(3	
 % "'	  		 "' "'A -,, #'(3 %	 "'
 
 D%%''D!!111&&4?CIA a'***##(D((:6::D""111''+1A q((##(D((:6::D***D**6<V<<D!!-*D**6<V<<Dq	s   H

H
c                N     dj                   fd|D              }|r|dz  }|S )Nr,  c              3     K   | ]7  \  }}|d v s|j                   j                  k(  r |j                  fi  9 yw))Nr  N)r  r   r  )r9  prefixr  r  r  s      r  r;  z1SQLCompiler._generate_prefixes.<locals>.<genexpr>  sI      
(0${*ldll>O>O.O &F%%d1b1(0s   =A r  )r  rW  r  r  r  s   `  ` r  rl  zSQLCompiler._generate_prefixes  s1     
(0
 

 cMFr  c                v   | j                   sy|r|dkD  rt        j                         }t        | j                   j	                               D ]g  }| j
                  |j                            \  }}}|j                  xs |j                  }||k(  xs |xr ||dz   k(  }	|r|	sV| j                   |   ||<   i n| j                   }|syt        |D cg c]  }|j                   c}      }
| j                  |
      dz   }|dj                  |j                         D cg c]  }| c}      z  }|dz  }|r{|dkD  rvt        |j	                               D ]Z  }| j
                  |j                            \  }}}| j                   |= | j                  ||f= | j
                  |j                         = \ |S c c}w c c}w )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   r,  , 
z
 )rU  r&   r  r  keysrW  ra  rb  rv   ri  get_cte_preambler   r  rV  )r  r  rY  rU  rY  rx  rt  rT  rb  is_rendered_levelrX  cte_texttxts                r  r  zSQLCompiler._render_cte_clause  s    yy ]Q.##%DDIINN,-040F0F**,1-	8X ++9)9)9$-$> %+N	]Q=N0N "  $5 IIcNS	 . 99Dt<tcmmt<=((83>FKK > >??E]Q.DIIK(040F0F**,1-	8X IIcN++Y,AB**3+A+A+CD )  = !?s   F1	F6
c                
    |ryy)NzWITH RECURSIVEWITHr  )r  ri  s     r  r  zSQLCompiler.get_cte_preamble	  s    #r  c                h    |j                   rt        j                  dd       |j                  rdS 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  s:    
   3
  %..{6B6r  c                x     | j                   |j                  t        t        j                     fi |}|rd|z   S y)z5allow dialects to customize how GROUP BY is rendered.z
 GROUP BY r  )r  r  r  r!   comma_op)r  r   r  group_bys       r  r^  zSQLCompiler.group_by_clause  sG     1400$$i	0B0B&C
GI
 (**r  c                x     | j                   |j                  t        t        j                     fi |}|rd|z   S y)z5allow dialects to customize how ORDER BY is rendered.z
 ORDER BY r  )r  r  r  r!   r"  )r  r   r  r,  s       r  r_  zSQLCompiler.order_by_clause*  sG     1400$$i	0B0B&C
GI
 (**r  c                     y)Nz FOR UPDATEr  r   s      r  r
  zSQLCompiler.for_update_clause6  s    r  c                   |j                  dt        j                  |            D 	cg c]"  \  }}}}}	 | j                  |||f||	||d|$ }
}}}}}	ddj	                  |
      z   S c c}	}}}}w )NT)cols)r  r  r   r  
RETURNING r   )rk  r   _select_iterablesr  r   )r  rW  returning_colsr  r  r   r  r  r   r  r  s              r  returning_clausezSQLCompiler.returning_clause9  s    2 22411.A 3 #
"# )D((#	 %8#+%	 	 # 	 
, dii000-
s   'A.c                    d}|j                   #|d | j                  |j                   fi |z   z  }|j                  4|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  ri  zSQLCompiler.limit_clauseY  s    +K,$,,v/C/C"Jr"JJJD  ,##+%Jf.C.C!Jr!JJJDr  c                   ||j                   }|j                  }nddd}d}|j                  K|j                  }|r!|j                  |      r|j	                         } | j
                  |fi |}	|d|	z  z  }n|r|dz  }|O|r!|j                  |      r|j	                         }|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 r0  z	WITH TIESONLY)rg  _fetch_clause_optionsr.  _simple_int_clauserender_literal_executer  )
r  r   rh  require_offset"use_literal_execute_for_simple_intr  fetch_clause_optionsr  offset_clause
offset_strs
             r  rh  zSQLCompiler.fetch_clausec  s    !//L#)#?#? /45#I   ,"11M2--m< - D D F%m:r:J'*44D&&D#2--l;+BBD\0R029=
2E3K@fL D
 r  c
                r   |r|j                   |j                  |<   |s|r| j                  j                  |      }|rG|rE| j                  j	                  |      dz   | j                  j                  |j                        z   }n| j                  j                  |j                        }|	|	j                  |ur_|s]|r[|j                  |v rM| j                  d||j                           }|| j                  | j                  j                  d |            z   }|r||v r| j                  ||||   |      }|S y)Nr)  r  r  )fullnamer  r  r  r  r  r   r  r  rp  rj  r  )r  r   rd  r  rq  rr  
use_schemar  r  r  r  r  rQ  	anon_names                 r  visit_tablezSQLCompiler.visit_table  s9    ',~~Ke$V#}}>>uE.MM../?@mm))%**56  mm))%**5 (/*22%?,0

&>> $ : :!9%**!E!I  ? ?224C! C Ui/00	% 0& Jr  c                   |ri|j                   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 Tr   ON r  )r  rw  r  r  r)   r   r*   r   r   isouterr  onclause)r  r   rd  r  r  	join_types         r  
visit_joinzSQLCompiler.visit_join  s
   $$!!dii556djj667 99+I\\+I I(DII((!{>D  ,djj++!{>D	  /dmm.."-17	
r  c                "   |j                   j                         D ci c]%  \  \  }}}|d| j                  j                  fv r||' }}}}|j                  |v r+| j                  ||j                  ||j                     d      }||fS c c}}}w )Nr  T)r  rx  r  r   r   r  )r  rW  
table_textr   r  r  dialect_hintss          r  _setup_crud_hintszSQLCompiler._setup_crud_hints  s     04{{/@/@/B
/B+ )3 1 122 9/B 	 

 ::&33DJJdjj(A4J j((
s   *B
c                   | j                   j                  }|j                  }|j                  }|y|j                  r'| j
                  j                  |j                  d      }n&| j                  j                  |j                  d      }||z  r|S |j                  r3t        j                  d|d    d| j                   j                   d      y)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_explicitr2   r<  r   )r  r   sentinel_optssentinel_characteristics	sent_colsbitmasks         r  _get_sentinel_column_for_tablez*SQLCompiler._get_sentinel_column_for_table  s     GG#(#I#I ,44	#..77;;(AA1G ;;??(AA1G 7"#// )))A, (><<$$% &@
@  r  c              #     @ABCDK    j                   }|J |j                  sd }	nt        j                  |j                   }	t	        |      }
|j
                  r j                  j                  sd}d}nE j                  j                  r&|r) j                  r|j                  |j                  rd}d}nd}d}|rNt        t        dt        ||            d      D ]*  \  }\  }}t        |||g|	r	 |	|      gng d||
||
       , y |r,t!        j"                   j$                  j&                  |      }nd }|j(                  }|r ||      }d| d}|j+                  |d      } j                  j,                  }|rAt	         j.                        }t	        |j0                        }||z
  }t3        |||z
  |z        }t        d	t5        |            }t        d	t5        |            }d }d}|
|z  |
|z  rdnd
z   }|j0                  }|J |r$|D cg c]  \  }}}}|| ||      |f }}}}}d
xCD j6                  s j8                  r j8                  Ani At;        |d
         } A fd@|j<                  rd}!nd}!ddj?                  @fd|D               |! d}"| jA                  Afd|D              }#| jC                  |#      D ci c]  }||d
   |    }$}dBnd}"t;               }#i }$|j<                  rd| dBnd| dBt;               }%|j0                  D ]  }&|%jE                  |&d           |%r] jF                  }'|'J t        |'      D ()ch c]  \  }(})|)|%v r|( }*}(})t3        |*      CtI        |*      dz   Dt	        |*      DCz
  k(  sJ  jJ                  r9tM        jN                   jP                        }+tM        jR                  |+ ddB      B|r[|d
| },|d
| }-g |d
| g |d
| |r|}.nt	        |,      }.r,fdtU        |.      D        D /01cg c]  \  }/}0}1|/|0|1f }}0}/}1 j6                  r|jV                  }2|2t	        |,d
         k(  rdx}3}4|,}5n|,d
   d C }3|,d
   Dd  }4CDfd|,D        }5|j<                  r'dj?                  Bfdt        |,      D              d d }6nB|.z  d d }6 jJ                  r9|2d
kD  r4|4rJ Cdz   }7|2|.z  |7z   }8tY         fdtU        |7|8      D              }9|6|9z  }6|j+                  d|6      }:tY        tZ        j\                  j_                  |5            };|3|;z   |4z   };ng }<|$ja                         };t        |,      D ]  \  }=}|"j+                  dtc        |=            }>|j<                  r|>j+                  dtc        |=            }>|<je                  |>       |;jE                  |#D ci c]  }| d|= ||    c}        |j+                  ddj?                  |<            }:t        |:|;||,|	r|-D ?cg c]
  }? |	|?       c}?ng |.|||d
       |dz  }|rZy y c c}}}}w c c}w c c})}(w c c}1}0}/w c c}w c c}?w w)NTFzKSequence[Tuple[_DBAPISingleExecuteParams, _MutableCoreSingleExecuteParams]]r   r  r&  r'  __EXECMANY_TOKEN__zList[Sequence[Any]]r   c                    | D ]G  }j                  ||      }|j                  j                  d|iz  j                  d| diz        }I |S )Nr   __EXECMANY_INDEX__)r  r  r>  )r  	formattedr:  rP  r  s      r  apply_placeholderszISQLCompiler._deliver_insertmanyvalues_batches.<locals>.apply_placeholders  sg    C,00c:C ) 1 1))VSM9))!cU*<#=>?!I   ! r  z, _IMV_VALUES_COUNTERr  r   c              3  :   K   | ]  \  }}}} ||        y wr  r  )r9  r$  r[  	bind_keysr\  s       r  r;  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  s)      62D.Aq)Y #9i82Dr  c              3  Z   K   | ]"  \  }}}}|D ]  }j                  ||        $ y wr  r/  )r9  r$  r^  r:  rP  s       r  r;  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  s<      4*<&Aq!Y$C #&&sC0$ 1*<   (+z, _IMV_VALUES_COUNTER), z), r  z\d+r  c              3  H   K   | ]  }D ]  \  }}}| d | ||f   yw)r$  Nr  )r9  r~  r:  len_r  generic_setinputsizess        r  r;  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>0  s>      /%>E.CNCs  5%)45.C 6%>r  r  c              3  (   K   | ]	  }|   y wr  r  )r9  r}  expand_pos_lower_indexexpand_pos_upper_indexs     r  r;  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>E  s"      &!&A 01GH!&s   c              3  Z   K   | ]"  \  }}j                  d t        |             $ yw)_IMV_VALUES_COUNTERN)r  r   )r9  r  r$  executemany_values_w_commas      r  r;  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>L  s5        )91 7>> 5s1v )9r`  c              3  >   K   | ]  }j                    |   y wr  )r@  )r9  r  r  s     r  r;  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>i  s)      &!2A  >>?sC!2r  EXECMANY_INDEX__rh  __)3rL  rP  r@  rO  r  rE  r  supports_default_metavaluesupports_multivalues_insertr  rN  rL  r  r   r  rT  	functoolspartialr  r  rF  r  insertmanyvalues_max_parametersr:  rH  minr  rb  rP  r~   rR  r   r$  r  rw  r4  r@  rE  r]  r^  r@  r  rangerJ  r=  r  r  from_iterablerU  r   r  )Er  r/  r0  compiled_parametersrc  
batch_sizerK  r  imv_sentinel_from_params	lenparamsuse_row_at_a_time
downgradedr\  paramcompiled_paramrstimv_single_values_exprexecutemany_values
max_paramstotal_num_of_paramsnum_params_per_batchnum_params_outside_of_batchbatchescompiled_batchesrX  r]  rH  r  r:  r	  stall_keysimv_values_counterformatted_values_clausekeys_to_replacebase_parametersall_names_we_will_expandr  r4  rP  r   all_expand_positionsescapedrY  compiled_batchr[  new_keyrb  r  num_ins_paramsextra_params_leftextra_params_rightbatch_iteratorexpanded_values_stringr  rx   r  rU  rV  replaced_values_clausesr  fmvr^  r\  rP  ri  re  rf  sE   `   `                                                           @@@@@r  !_deliver_insertmanyvalues_batchesz-SQLCompiler._deliver_insertmanyvalues_batchesI  s     $$&&$(!$,$7$7((%! 
O	t||'N'N !%J99#$$%%-1N1N
 !%J %J5>a
$78 6115. -)G 1 /~>?+ 6. ##77%9C
 C!$!7!7%()?%@" !7 8:%%&8:NO	 \\AA
"%doo"6#&s'='=#> #&:: ( "==+,J ,d:.>?!4(;#<
 HL!Z/Z'AQ
 !33!--- +="*<&CdB c3t9b)*<  " ;<;!7&&%)%<%<"%'":a=)H! ''%<"%'"*+DII 62D6 - , ""!''#
 '33 4*<4 O $..??C Z]3''?   *,&&(#!eO O''.//GH + 011G0H-L*14$..(//Q8 / (".."... &/{%;(%;	T77 %; % (
 *--A)B&),-A)BQ)F&,--0FFGG ""))D$G$GH-/VVy$d,F.* Aj)E-a
;N$&GAj!-/Qz*%/"%(Z"$/%*+=%>/+/*s dC(/ ( + !$!B!B "Sq]2=??%(:%*N(-a1H2H(I%).q2H2I)J&&!&&N
 ++   )2%(8	   r.* 46HHr.* &&>A+=  2112Q6E(,>?%GC !& &!&uc!2& !I .Di-O*%.%6%6(*@&" ',OO11.A'#
 &)*() $ +-'&5&:&:&<# )% 0HAu199*CFC //!kk*?QH+2237'..>MNosC51#c
2oN !1 &/%6%6(II56&"
 )"#' - :HH2*2.H"'   MHI o"P:(D+x O IsX   HY%Y
1B"Y%Y	#A;Y%Y.B5Y%#Y3FY%Y
9Y%Y &Y%?&Y%c                     |j                   | fi |}|j                  }|||d<   d}n j                   }|r-d _         j                  s| _         j
                  s| _         j                  j                  t               t               |d       d}d } j                  r|g }t        j                   |||fd|i|} j                  rB|@t        |      } j                  r) j                   xj                  |z  c_        n| _        |j                  }	|	sn j                  j                   sX j                  j"                  sB j                  j$                  s,t'        j(                  d j                  j*                  z        |j,                  r j                  j.                  s,t'        j(                  d j                  j*                  z         j0                  s|j2                  r!|j4                  rt'        j(                  d	      |j                  }	n|j                  }	 j6                  }
 j                  j                   }d
}|j8                  r!|  j:                  ||j8                  fi |z  }|dz  }|
j=                  |j>                        }|j@                  r jC                  ||      \  }}|jD                  r jG                  ||       ||z  }|	s|s,|ddjI                  |	D cg c]	  \  }}}}| c}}      z  z  }|jJ                  }d }d }d} j0                  xs |j2                  }|r|jL                  }||sJ |	D ci c]
  \  }}}}|| }}}}g }|D ]7  }||vrd } n/ jO                  |      }|||   vrd } n|j                  |       9 |@ j                  jP                  tR        jT                  z  rd}n|d   jV                  rJ d       tY        |      tY        |      z   } j[                  |||      } j\                  r|d|z   z  }nd }|j^                    j`                   j                  d   d   fddi|} jb                  rL j                  jd                  r6|st         j                        nd }|d jg                  |d      |z  }n|d|z  z  }n|	sf|rd|dz  }|rti        d j                  jj                  tm        d|	      ||j4                  |jn                  d u||rt        |      nd|	       _8        n}|j,                  r*|ddjI                  d |jr                  D              z  }nGdjI                  tm        d|	      D cg c]	  \  }}}}| c}}      }|r|r j                  jP                  tR        jt                  z  r|jv                  sd} j                  jP                  tR        jx                  z  } djI                  d t{        |	      D              }!| r$djI                   fdt{        |	      D              }"n|!}"|d|" d| d|! d z  }nd}|d!| d"z  }ti        d|tm        d|	      ||j4                  |jn                  d u||rt        |      nd|||#       _8        n	|d!| d"z  }|jn                  '  j`                  |jn                  fi |}#|#r|d|#z   z  }|r j\                  s|d|z   z  } jb                  rE j                  jd                  s/|st         j                        nd } jg                  |d      |z   } j                  j}                  d       |S c c}}w c c}}}w c c}}w )$Nr\  FTr  r   rP  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   zTsentinel selection rules should have prevented us from getting here for this dialectr  r,  r  r+  r  rX  r  z DEFAULT VALUESrG  )rK  rL  rN  rO  rQ  z VALUES c              3  R   K   | ]  }d dj                  d |D              z   ! yw)r   r   c              3  *   K   | ]  \  }}}}|  y wr  r  )r9  r$  r  s      r  r;  z5SQLCompiler.visit_insert.<locals>.<genexpr>.<genexpr>  s      L^>1a^s   Nr  )r9  crud_param_sets     r  r;  z+SQLCompiler.visit_insert.<locals>.<genexpr>  s3       +N yy L^ LLN*Ms   %'c              3  ,   K   | ]  \  }}d |   ywpNr  )r9  r  r$  s      r  r;  z+SQLCompiler.visit_insert.<locals>.<genexpr>  s      ),IDAq!A3,Is   c              3     K   | ]L  \  }^}}j                  |j                  |j                  j                  j                        d |        N ywr  )r  r  r  r  )r9  r  r  r$  r  s       r  r;  z+SQLCompiler.visit_insert.<locals>.<genexpr>  sX      4 1N9C! !11 # # @ @ N"#A3
 1Ns   AAz SELECT z FROM (VALUES (z)) AS imp_sen(z#, sen_counter) ORDER BY sen_counterz	 VALUES (r'  )rE  rF  rH  rJ  rK  rL  rN  rO  rP  rQ  rR  )?rZ  r/  r  r1  r  r%  r  r~   rb  r   _get_crud_paramsr  rE  rR  single_paramsr  supports_default_valuesrn  supports_empty_insertr2   r  r   _has_multi_parametersro  r7  
_returning_sort_by_parameter_orderr  rm  rl  format_tabler   r  rH  r  r  r   use_insertmanyvaluesuse_sentinel_columnsr,  rJ  ra  rj  _insert_sentinelr  r+  r;  r   r  rU  cte_follows_insertr  rD  default_metavalue_tokenr   _post_values_clauserL  all_multi_paramsrl  is_default_metavalue_onlyrm  r  r  )$r  insert_stmtrP  r\  r  r%  r  counted_bindparamcrud_params_structcrud_params_singler  r  r  rF  r$  r	  r  named_sentinel_paramsadd_sentinel_colsrQ  r*  r  param_names_params_by_col_add_sentinel_col
param_namer+  select_textr  r  r  embed_sentinel_valuerender_bind_castscolnamescolnames_w_castpost_values_clauses$   `                                   r  visit_insertzSQLCompiler.visit_insert  s    ;::
!#
 $--#!-B~H::~H DM)))6&%%%2"

#&5 #)	
  ! ??|3
 !#!22	

 0
 
 ??0< #$5 6""))5**.??*->D*/== #LL88LL;;LL66""!\\../  ..<<;;&&137<<3D3DE  '';+A+A66&&I  "4!A!A!3!A!A=="&,,"F"F  +D++[2268 D 	**;+<+<=
 22;
KMAz((++K<
%<Gdii+=>+=-!T1a+=>  D  2FF9= !00JK4J4J 2 G G ,+++ 3E"2D.Q; $2D  " )+%):%(>04-!%!C!C)"J "8I)JJ04-)00< *; )0 GG6HHI -1) $5Q#7#H#H DH "&n!5=N8O!O#44$,  5   --...  $)&$,,

234BFJLK yyT\\<<7?DJJT++&304 ,     ++#(?%%D#):LL889;M &#<< $77tC%62C-.&7#*&& 00		  +=*M*M  D )-		 +/9*++1eQ +)% $%GG6MMN
 0II ,0( GG6NNO &
  $yy ),56H,I)  H ) +/)) 4 1::L0M4 + +3"?"3 4$$=#> ?&&.Z 0//D ,1(i(A'B!DDD):$)'@'+9*( 3D#<< $77tC%62C-.(=&7)=)*&0 )$=#>a@@**6!-//"35" "000D$B$BC***D99T\\<<3;C

OM''"/,0 (  	  	

rs ?0"^s   ;]]%;],
c                     y)z3Provide a hook for MySQL to add LIMIT to the UPDATENr  )r  update_stmts     r  update_limit_clausezSQLCompiler.update_limit_clause      r  c                     y)z3Provide a hook for MySQL to add LIMIT to the DELETENr  )r  delete_stmts     r  delete_limit_clausezSQLCompiler.delete_limit_clause  r  r  c                6    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.

        Trd  r  r  )r  r  
from_tableextra_fromsr  s        r  update_tables_clausez SQLCompiler.update_tables_clause  s*     8,z,,T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 |}t        rt        |t              sJ |j                  }|||d<   d}n| j
                   }|r-d| _        | j                  s|| _        | j                  s|| _        | j                  t        z  r1t        i t                     }| j                  t        z  }|r|| _        nd }d}|j                  }t!        |      }	|	rDt        t#        |j$                              }
|D cg c]	  }||
vs| }}|
j'                  |      }ng }|j$                  h}| j
                  j)                  |||d       d}|j*                  r!| | j,                  ||j*                  fi |z  } | j.                  ||j$                  |fd|i|}t1        j2                  | |||fi |}|j4                  }|j6                  r| j9                  ||      \  }}nd }|j:                  r| j=                  ||       ||z  }|dz  }|dj?                  d	 tA        d
|      D              z  }| jB                  s|jD                  r>| jF                  r2|d| jI                  || jB                  xs |jD                  |      z   z  }|r, | jJ                  ||j$                  ||fd|i|}|r|d|z   z  }|jL                  r) | jN                  |jL                  fd|i|}|r|d|z   z  }| jQ                  |      }|r|d|z   z  }| jB                  s|jD                  r>| jF                  s2|d| jI                  || jB                  xs |jD                  |      z   z  }| jR                  r.|stU        | j
                        nd }| jW                  |      |z   }|r|J |jY                  d       | j
                  j[                  d       |S c c}w )Nr\  FTr  zUPDATE r  z SET r   c              3  6   K   | ]  \  }}}}|d z   |z     yw)=Nr  )r9  r$  r	  r  s       r  r;  z+SQLCompiler.visit_update.<locals>.<genexpr>  s.      
&!4 3J&s   zList[Tuple[Any, str, str, Any]]r,  r   WHERE r  UPDATEr  r  ).rZ  r   r  rA   r/  r  r2  r  r%  rh  rv  rz  r~   rw  r  _extra_fromsr&  r*   r   r   r  rm  rl  r  r   r  r  r  rH  r  r  r   r   r7  r  r;  r+  r  r  r  r  rU  r  r  r  r  )r  r  r\  r  r%  r  r  r  r  is_multitable
main_fromsr  render_extra_fromsr!  r  rF  r  crud_paramsrG  extra_from_textr  ri  r  s                          r  visit_updatezSQLCompiler.visit_update6  sc    ;::
!#
 m^<<<#--#!-B~H::~H DM)))6&%%%2"<<44$R/K<<,6L#. K L#00[)];+<+<=>J&"&a!:*=;  " )..{;O!#*001O

#2 /)	
   +D++[2268 D /T..
 $	

 

 "22+}h
:<
 )66(,(>(>Z)%M: !M((++K<
		 
%)1;&
 
 	
 ""k&<&<--d33++E{/E/E(0 4    5d55!!"	
 ( O o--&&111++9DHJA 	A%//<C,&&D ##{'='=00C$//''A;+A+A$, 0   D 993;C

OM***G$ND***x0

rS"s   	OO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  r  r  r  r  r  s         r  delete_extra_from_clausez$SQLCompiler.delete_extra_from_clause  s     "%
 	
r  c                .     |j                   | fddd|S )NT)rd  r  r  )r  r  r  r  r  s        r  delete_table_clausezSQLCompiler.delete_table_clause  s,    ,z,,
d
.0
 	
r  c                    |j                   || fi |}|j                  }|||d<   d}n| j                   }|r-d| _        | j                  s|| _        | j
                  s|| _        | j                  t        z  r1t        i t                     }| j                  t        z  }|r|| _        nd }d}|j                  }|j                  hj                  |      }	| j                  j                  |	|	|d       d}
|j                   r!|
 | j"                  ||j                   fi |z  }
|
dz  }
	 | j%                  ||j                  ||      }t+        j,                  | |||fi | |j.                  r| j1                  ||      \  }}nd }|j2                  r| j5                  ||       |
|z  }
| j6                  s|j8                  r>| j:                  r2|
d| j=                  || j6                  xs |j8                  |	      z   z  }
|r, | j>                  ||j                  ||fd
|i|}|r|
d|z   z  }
|j@                  r) | jB                  |j@                  fd
|i|}|r|
d|z   z  }
| jE                  |      }|r|
d|z   z  }
| j6                  s|j8                  r>| j:                  s2|
d| j=                  || j6                  xs |j8                  |	      z   z  }
| jF                  r.|stI        | j                        nd }| jK                  |      |
z   }
|r|J |jM                  d       | j                  jO                  d       |
S # t&        $ r@ | j%                  ||j                  |      }|r| j)                  |j                  |      }Y Aw xY w)Nr\  FTr  zDELETE FROM )r  r,  r  r  r  r  DELETEr  r  )(rZ  r/  r  r0  r  r%  rh  rv  rz  r~   rw  r  r  r   r   r  rm  rl  r  	TypeErrorr  r   r  r  rH  r  r  r7  r  r;  r+  r  r  r  r  rU  r  r  r  r  )r  r  r\  r  r%  r  r  r  r  r!  r  rF  r$  rG  r  r  ri  r  s                     r  visit_deletezSQLCompiler.visit_delete  s   :::
!#
 $--#!-B~H::~H DM)))6&%%%2"<<44$R/K<<,6L#. K L#00&,,-33K@

#2 /)	
   +D++[2268 D 		M11!!'	 2 J 	dKOBO(,(>(>Z)%M: !M((++K<
 ##{'='=,,C$//''A;+A+A$, 0   D ;d;;!!	
 ( O o--&&111++9DHJA 	A%//<C,&&D ##{'='=00C$//''A;+A+A$, 0   D 993;C

OM***G$ND***x0

rU  	M 11[..J LL!2!2LL	Ms   +M ANNc                >    d| j                   j                  |      z  S )NzSAVEPOINT %sr  format_savepointr  savepoint_stmtr  s      r  visit_savepointzSQLCompiler.visit_savepointb  s     > >~ NNNr  c                >    d| j                   j                  |      z  S )NzROLLBACK TO SAVEPOINT %sr  r  s      r  visit_rollback_to_savepointz'SQLCompiler.visit_rollback_to_savepointe  s#    )DMM,J,J-
 
 	
r  c                >    d| j                   j                  |      z  S )NzRELEASE SAVEPOINT %sr  r  s      r  visit_release_savepointz#SQLCompiler.visit_release_savepointj  s#    %(F(F)
 
 	
r  )r  rk   r/  r  r  r  rf  r3  rg  r&  rh  rt  r|  zOptional[SQLCompiler]r  r   )r  rH  )r  r6  )r  zDict[Any, Any])r  zMutableMapping[CTE, str])r  zVMutableMapping[str, Union[_BindProcessorType[Any], Sequence[_BindProcessorType[Any]]]])r  r6   )NT)r  r  r  r&  r  r.  )NNTNTF)r  r  r  r  r  r&  r  Optional[int]r  r&  rd  r&  r  rj   F)r0  rj   re  r&  r  r.  )r  zCallable[[Any], str]r  )NFFNr  )NTr  N)r   ColumnClause[Any]r  Optional[_ResultMapAppender]r  r&  r  r  r  z Optional[_AmbiguousTableNameMap]r  r   r  r   r  )NF)r	  rK   r  r   r  r   )r	  rL   r  r   r  r   )r	  rI   r  r   r  r   )r4  Function[Any]r  r  r  r   r  r   )r4  r  r  r   r  r   )FNNr  )NFNN)
r   BinaryExpression[Any]r  r   r  r&  r  r   r  r   )r   r  r@  r   r  r   r  r   )FFFFF)r  r   r  zsqltypes.TypeEngine[Any]r  r   )rB  r   r   rC   r  r   )r   r   r  r   )FFNNNN)r   r   r  r&  r  r&  rN  rH  r   zOptional[TypeEngine[Any]]rO  zOptional[Set[str]]rP  rJ  r  r   r  r   )rY  rX   rd  r&  rq  r&  rr  zOptional[_FromHintsType]r\  Optional[CTE]r  zOptional[FromLinter]rT  zselectable._CTEOptsr  r   r  rH  )FFFNFFNN)
r   r   r   r   r  r  r  r  r  r  )NNNTFFT)r   rY   r  rH  r  rH  )FFNNNFN)r   r*  r  zTuple[str, _FromHintsType])r   r*  r  r   r  r   
rW  r@   r*  zSequence[_ColumnsClauseElement]r  r&  r  r   r  r   )NFF)FFFNTNNN)r   rS   r  rM  )r/  r   r0  rf   rv  z%List[_MutableCoreSingleExecuteParams]rc  rW  rw  rI  rK  r&  r  r  r  z Iterator[_InsertManyValuesBatch]r|  )r  r?   r\  r  r  r   r  r   )r  r  r  r	  EXTRACT_MAPr9  r&   r  r-  r
  r  COMPOUND_KEYWORDSr[  r0  r1  r2  r4  r5  r7  r8  r;  r<  r=  rA  rB  rC  rD  rE  rF  rG  rI  rK  rL  rM  	frozensetrN  rO  r  rP  r'  postfetch_lastrowidrQ  r4  rR  rS  rT  r]  r_  r  r  patternr  r  r  r[  ru  r  rB  r  ro_memoized_propertyr  r  r  r  memoized_propertyr  memoized_instancemethodr  
contextlibcontextmanagerr  rz  ry  r  r  r  r  r  r  r  r{  preload_moduler'  r,  rG  rR  rT  r_  re  rh  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  r%  r/  r2  r7  r<  rB  r>  rP  rM  rJ  re  ra  r
  rt  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rr  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  rI  r  r  r$   _CTEOptsrh  r  r  r  r  r  r  r  r  r  rp  r  r  r  r  r  r  r  r  rM  r   r  r  r  r  r  r  r  rl  r  r  r  r^  r_  r
  r+  ri  rh  r>  rD  rH  r,   
CLIENTSIDEra  rk  SENTINEL_DEFAULTNONErh  ri  rO  r   rg  rM  rU  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r    s    K 			
  ; : /.66F)HdHdHd
 +*% .0O*/ .0O*/$ BF>E K((I--6 %$4 ',t+ 5:+T9
 "OT! B!! %('
 .-
 &+d* "OT! "d! ).- !ND  !&% =A "9@ +/-.
 6:295929=A:A<EK9G
 :C6D
 8<4F
   % 	    (,K$+ .2*1.2+2FD
,, 32 GF&BJJ'LM"

#45$"**$$
%Q'<'D'D&EF # # C C )-/3 %%59PP +P &	P
 -P P P 3P Pd = =$ 
 0 ( (  M  MD G G 
  
!! ".  .9vGR 



 
8#  
 6:!
2
 
 
	
2 6:GK!'+ %~2~ E~ 	~
 %~ ~ ~ 
)~@ 
!!$ "$L 
3 
3  %C3C C 
	CJ T34
 5
 43	  
T34P 5 Pd 
T34, 5 ,\>@OO .3-
` .3+` !#"/b

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

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


  %	%  	
  
2GG 
I IJAEBFAEBFAEBF

	
AE


+
7:
BE
	

+
7:
BE
	

+
7:
BE
	
 $" cJ$ $!%	DB%%!9%	%N&6	*$ #&*484815AA A 	A
 $A 2A  2A /A A 
AFC .2&*,0(;
(;(;E(BVV V 	V
 ,V $V *V &V V 
Vp30 bH0?"$L9(

 
 !	

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

AF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                     y)Nz<name unknown>r  r  s     r  r  z$StrSQLCompiler._fallback_column_name  s    r  zsqlalchemy.engine.urlc                T   |j                   dk7  rt        j                  j                  } |j                  j                  |j                         j                                }|j                  |d |       }t        |t              s |j                  |fi |S t        | 1  ||      S )Nr   )r|  )stringify_dialectr&   r#  
engine_urlURLr   get_dialectstatement_compilerr  r  r  r  r  )r  r  r  r  urlr  compilerr  s          r  r  z,StrSQLCompiler.visit_unsupported_compilation  s    $$	1..++CMcggnnW%>%>?KKMOG114 2 H h7'x''6266w4WcBBr  c                ~     | j                   |j                  fi |d | j                   |j                  fi |dS )Nr*  r+  )r  r   r   r{  s       r  visit_getitem_binaryz#StrSQLCompiler.visit_getitem_binary  s:    DLL++DLL,,
 	
r  c                *     | j                   ||fi |S r  r  r{  s       r  visit_json_getitem_op_binaryz+StrSQLCompiler.visit_json_getitem_op_binary      (t((@R@@r  c                *     | j                   ||fi |S r  r  r{  s       r  !visit_json_path_getitem_op_binaryz0StrSQLCompiler.visit_json_path_getitem_op_binary  r  r  c                @    d| j                   j                  |       dS )Nz<next sequence value: >)r  format_sequencerS  s      r  rM  zStrSQLCompiler.visit_sequence  s#    $T]]%B%B8%L$MQO	
r  c          
         t        j                  |      D cg c]  }| j                  d |ddi        }}ddj                  |      z   S c c}w )NTFr(  r   )r   r)  r  r   )r  rW  r*  r  r  r  r  s          r  r+  zStrSQLCompiler.returning_clause  s]     ++N;
; %%dAtUB?; 	 
 dii000	
s   A
c                P     dd<   ddj                   fd|D              z   S )NTrd  r  r   c              3  H   K   | ]  } |j                   fd i  ywrr  Nr  r9  r  r  r  r  s     r  r;  z4StrSQLCompiler.update_from_clause.<locals>.<genexpr>  s0      #
  !A  BBrB r  r  r  s   `   ``r  r  z!StrSQLCompiler.update_from_clause  s3     8 #
 #
 
 
 	
r  c                P     dd<   ddj                   fd|D              z   S )NTrd  r   c              3  H   K   | ]  } |j                   fd i  ywr'  r  r(  s     r  r;  z:StrSQLCompiler.delete_extra_from_clause.<locals>.<genexpr>  s0       
  !A  BBrB r  r  r  s   `   ``r  r  z'StrSQLCompiler.delete_extra_from_clause  s3     8dii  
  
 
 
 	
r  c                     y)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\HRHHr  c                *     | j                   |dfi |S )Nz <not regexp> r.  r{  s       r  r  z/StrSQLCompiler.visit_not_regexp_match_op_binary  s    ,t,,V5ELLLr  c                    d |j                   j                  | fi |d |j                  j                  | fi |dS )Nz<regexp replace>(r   r'  )r   r  r   r{  s       r  r  z-StrSQLCompiler.visit_regexp_replace_op_binary  s>    *FKK**4626+FLL++D7B7
 	
r  c                    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  s>    *DKK**4:6:.DOO..t>v>
 	
r  r  )r  r  r  r	  r  r&   r	  r  r  r  r   rM  r+  r  r  r  r  r  r  r  r2  r  r  s   @r  r  r  p  s    &  T01C 2C
AA

11 81
 "1 1 
1

%IM

r  r  c                     e Zd ZdZer	 	 	 d2	 	 	 	 	 	 	 	 	 d3dZej                  d4d       Zej                  d        Z
	 	 	 d5	 	 	 	 	 	 	 d6dZd Zd Zd	 Zd
 Zd7dZ	 d8dZd Zd Zd9dZ	 d:dZd Z	 d7	 	 	 	 	 d;dZd Zd Zd Zd Zd Zd Zd Zd Zd8dZ d Z!d Z"d Z#d Z$d  Z%d<d!Z&d=d"Z'd# Z(d$ Z)d% Z*	 	 	 	 	 	 d>d&Z+d' Z,d( Z-	 	 	 	 	 	 d?d)Z.	 	 	 	 	 	 d?d*Z/	 	 	 	 d@d+Z0	 	 	 	 d@d,Z1	 	 	 	 d@d-Z2dAd.Z3d/ Z4d0 Z5d1 Z6y)BDDLCompilerTc                     y r  r  r  s         r  r  zDDLCompiler.__init__  s     r  c                f    | j                   j                  | j                   d | j                        S )NrW  )r  r  r  r>  s    r  r  zDDLCompiler.sql_compiler  s/    ||..LL$T5N5N / 
 	
r  c                .    | j                   j                  S r  )r  r  r>  s    r  type_compilerzDDLCompiler.type_compiler  s    ||222r  Nc                     y r  r  r  s       r  r  zDDLCompiler.construct_params  s     r  c                   |j                   }t        |j                  t        j                        r|j                         }| j                  }|j                  |j                        }t        |      dk(  r|d   d}}n
|d   |d   }}|j                  d|       |j                  d|       |j                  d|j                  |j                               | j                  j                  |j                  |z        S )Nr   r   r  r  r   r#   r;  )contextr  targetr#   rS   rU  r  format_table_seqr  r  r  r  r  r/  )r  ddlr  r;  r  pathr   schs           r  	visit_ddlzDDLCompiler.visit_ddl  s    ++cjj&,,/llnG}}H,,SZZ8D4yA~!!Wbs!"XtAwsw.x-z8+@+@+LM  223==73JKKr  c                x    d}|j                   r|dz  }|| j                  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  s9    $$Ddmm11&..AAAr  c                    d}|j                   r|dz  }|| j                  j                  |j                        z  }|j                  r|dz  }|S )NzDROP SCHEMA 
IF EXISTS  CASCADE)	if_existsr  rE  r  cascader  dropr  r  s       r  visit_drop_schemazDDLCompiler.visit_drop_schema  sK    >>L D++DLL99<<JDr  c                ,   |j                   }| j                  }d}|j                  r!|dj                  |j                        dz   z  }|dz  }|j                  r|dz  }||j                  |      dz   z  }| j                  |      }|r||dz   z  }|dz  }d}d}|j                  D ]P  }	|	j                   }
	 | j                  |	|
j                  xr |       }|||z  }d	}|d
|z   z  }|
j                  rd}R | j                  ||j                         }|r||d
z   |z   z  }|d| j#                  |      z  z  }|S # t        j                  $ rE}t        j                  d|j                  d|
j                  d|j                  d         |d }~ww xY w)Nz
CREATE r,  zTABLE rC  r&  
Ffirst_pkr  	Tz(in table 'z', column 'z'): r   ) _include_foreign_key_constraintsz
)%s

)r  r  rm  r   rD  r  create_table_suffixr  r  r?  r2   r  descriptionr   argscreate_table_constraintsinclude_foreign_key_constraintspost_create_table)r  r   r  r   r  r  rU  r  rR  create_columnr   	processedceconsts                 r  visit_create_tablezDDLCompiler.visit_create_table!  s   ==??CHHU__-33D$$D%%e,s22"66u='#--D	 #^^M"**F LL!F,>,>,Ox< ) 	 (I%D &ID9,,D%%#H ,$ ---3-S-S . 
 I$u,,Dd44U;;; ## &&((&++rwwqzC s   5AD;;FA FFc                     |j                   }|j                  ry  j                  ||      }dj                   fd|j                  D              }|r|d|z   z  }|S )NrQ  r,  c              3  @   K   | ]  }j                  |        y wr  )r  r9  r   r  s     r  r;  z2DDLCompiler.visit_create_column.<locals>.<genexpr>\  s      
7IDLL$7Is   )r  systemget_column_specificationr   constraints)r  r   rR  r  r   r  r^  s   `      r  visit_create_columnzDDLCompiler.visit_create_columnU  sd    ==,,Vh,G 
7=7I7I
 
 C%KDr  c                l    g }|j                   r|j                  |j                          |j                  }||j                  |      }n
t	               }|j                  |j                  D cg c]  }||j                   ur||vr| c}       dj                  d  fd|D        D              S c c}w )Nz, 
	c              3  $   K   | ]  }|| 
 y wr  r  )r9  r  s     r  r;  z7DDLCompiler.create_table_constraints.<locals>.<genexpr>{  s#      
 } r  c              3     K   | ]I  }|j                        r6j                  j                  rt        |d d      sj	                  |       K yw)	use_alterFN)_should_create_for_compilerr  supports_alterrD  r  rb  s     r  r;  z7DDLCompiler.create_table_constraints.<locals>.<genexpr>}  sI      "-J::4@33":{EB Z("-r  )r?  r  foreign_key_constraintsr  r~   r  _sorted_constraintsr   )r  r   rT  r  re  all_fkcs	omit_fkcsr  s   `       r  rX  z$DDLCompiler.create_table_constraintsd  s    
 u00100+7 ++,LMII 222AE---!92D 2	
 }} 
"-
 
 	
s   .B1c                x    d}|j                   r|dz  }|| j                  j                  |j                        z   S )Nz
DROP TABLE rH  )rJ  r  r  r  rL  s       r  visit_drop_tablezDDLCompiler.visit_drop_table  s6    >>L Ddmm00>>>r  c                R    d| j                   j                  |j                        z   S )Nz
DROP VIEW r  r  r  r  rM  r  s      r  visit_drop_viewzDDLCompiler.visit_drop_view  s      : :4<< HHHr  c                `    |j                   "t        j                  d|j                  z        y )Nz,Index '%s' is not associated with any table.)r   r2   r  r   )r  r~  s     r  _verify_index_tablezDDLCompiler._verify_index_table  s0    ;;"">K  r  c           	         |j                   } j                  |        j                  }d}|j                  r|dz  }|j                  t        j                  d      |dz  }|j                  r|dz  }| j                  ||      d|j                  |j                  |      d	d
j                   fd|j                  D              dz  }|S )NzCREATE UNIQUE z0CREATE INDEX requires that the index have a namezINDEX rC  include_schemar@  r<  r  r   c              3  Z   K   | ]"  }j                   j                  |d d       $ yw)FTr  r  N)r  r  )r9  r	  r  s     r  r;  z1DDLCompiler.visit_create_index.<locals>.<genexpr>  s:       .D !!))T *  .r`  r'  )r  rx  r  r   r   r2   r  rD  _prepared_index_namer  r   r   expressions)r  r   r|  include_table_schemar  r~  r  r  s   `       r  visit_create_indexzDDLCompiler.visit_create_index  s       '==<<ID::""B  	$$D%%eN%K!!(< "  II  "--	 
 	
 r  c                    |j                   }|j                  t        j                  d      d}|j                  r|dz  }|| j                  |d      z   S )Nz.DROP INDEX requires that the index have a namez
DROP INDEX rH  Tr{  )r  r   r2   r  rJ  r  )r  rM  r  r~  r  s        r  visit_drop_indexzDDLCompiler.visit_drop_index  s^    ::""@  >>L Dd//d/KKKr  c                    |j                   &| j                  j                  |j                         }nd }|r|r| j                  j                  |      }nd }| j                  j	                  |      }|r|dz   |z   }|S Nr)  )r   r  r  r  format_index)r  r~  r|  r  schema_name
index_names         r  r  z DDLCompiler._prepared_index_name  sy     ;;"#}}>>u{{K#.--445EFKK]]//6
$s*Z7Jr  c                    d| j                   j                  |j                  j                        d| j	                  |j                        S )NALTER TABLE z ADD )r  r  r  r   r  r  r   r  s      r  visit_add_constraintz DDLCompiler.visit_add_constraint  s8    MM&&v~~';';<LL(
 	
r  c                    d| j                   j                  |j                        d| j                  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  sL    MM&&v~~622&&(9
 	
r  c                R    d| j                   j                  |j                        z  S )NzCOMMENT ON TABLE %s IS NULLrt  ru  s      r  visit_drop_table_commentz$DDLCompiler.visit_drop_table_comment  s'    ,t}}/I/ILL0
 
 	
r  c                    d| j                   j                  |j                  dd      d| j                  j	                  |j                  j
                  t        j                               S )NzCOMMENT ON COLUMN T)	use_tabler<  r   )r  format_columnr  r  r  r  r%   r  r  s      r  visit_set_column_commentz$DDLCompiler.visit_set_column_comment  sZ    MM''$4 (  22&&(9	
 	
r  c                V    d| j                   j                  |j                  d      z  S )NzCOMMENT ON COLUMN %s IS NULLT)r  )r  r  r  ru  s      r  visit_drop_column_commentz%DDLCompiler.visit_drop_column_comment  s/    -0K0KLLD 1L 1
 
 	
r  c                @    t        j                  | t        |            r  r  r  s      r  visit_set_constraint_commentz(DDLCompiler.visit_set_constraint_comment  s    --dDLAAr  c                @    t        j                  | t        |            r  r  ru  s      r  visit_drop_constraint_commentz)DDLCompiler.visit_drop_constraint_comment  s    --dDJ??r  c                   g }|j                   |j                  d|j                   z         |j                  |j                  d|j                  z         |j                  |j                  d|j                  z         |j                  |j                  d|j                  z         |j
                  |j                  d       |j                  |j                  d       |j                  |j                  d|j                  z         |j                  |j                  |j                  rdnd	       d
j                  |      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cycler   )r  identity_optionsr  s      r  get_identity_optionsz DDLCompiler.get_identity_options  s   %%1KK),<,F,FFG!!-KK*:*@*@@A$$0KK(8(A(AAB$$0KK(8(A(AAB&&2KK&&&2KK&!!-KK
%5%;%;;<!!-KK#3#9#9zJxx~r  c                    d}|j                   r|dz  }|| j                  j                  |j                        z  }|r||z  }| j	                  |j                        }|r|d|z   z  }|S )NzCREATE SEQUENCE rC  r,  )rD  r  r#  r  r  )r  r   r  r  r  optionss         r  visit_create_sequencez!DDLCompiler.visit_create_sequence  sn    !$$D--fnn==FND++FNN;C'M!Dr  c                x    d}|j                   r|dz  }|| j                  j                  |j                        z   S )NzDROP SEQUENCE rH  )rJ  r  r#  r  rL  s       r  visit_drop_sequencezDDLCompiler.visit_drop_sequence   s6    >>L Ddmm33DLLAAAr  c                d   |j                   }|j                  | j                  j                  |      }nd }|"t	        j
                  d|j                   z        d| j                  j                  |j                   j                        d|j                  rdnd||j                  rdS dS )Nz<Can't emit DROP CONSTRAINT for constraint %r; it has no namer  z DROP CONSTRAINT rH  r  rI  )
r  r   r  format_constraintr2   r  r  r   rJ  rK  )r  rM  r  r   formatted_names        r  visit_drop_constraintz!DDLCompiler.visit_drop_constraint&  s    \\
??&!]]<<ZHN!N!""!#'<<0  " MM&&t||'9'9: NNL2,,J.	
 	
 -/.	
 	
r  c                "   | j                   j                  |      dz   | j                  j                  j	                  |j
                  |      z   }| j                  |      }||d|z   z  }|j                  !|d| j	                  |j                        z   z  }|j                  7| j                  j                  r!|d| j	                  |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  rd  z$DDLCompiler.get_column_specification9  s    MM''/ll1199V :  	 008{W,,G??&sT\\&//:::G OO'66sT\\&//:::Gt||'M'M{"Gr  c                     yNr  r  r  r   s     r  rU  zDDLCompiler.create_table_suffixT      r  c                     yr  r  r  s     r  rZ  zDDLCompiler.post_create_tableW  r  r  c                    t        |j                  t        j                        r%| j	                  |j                  j
                        S y r  )r  server_defaultr#   DefaultClauserender_default_stringargr  s     r  r  z%DDLCompiler.get_column_default_stringZ  s8    f++V-A-AB--f.C.C.G.GHHr  c                    t        |t              r*| j                  j                  |t        j
                        S | j                  j                  |d      S )NT)r  )r  r   r  r  r%   r  r  )r  r   s     r  r  z!DDLCompiler.render_default_string`  sN    gs#$$99,,  $$,,WD,IIr  c                ^    |j                   r| j                  |      S | j                  |      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_constrainth  s-    %%55jAA..z::r  c                    d}|j                   %| j                  j                  |      }||d|z  z  }|d| j                  j	                  |j
                  dd      z  z  }|| j                  |      z  }|S Nr  CONSTRAINT %s z
CHECK (%s)FTr  r   r  r  r  r  r[  define_constraint_deferrabilityr  r   r  r  r  s        r  r  z"DDLCompiler.visit_check_constraintn      ??&!]]<<ZHN)(>99t0088e4  9  
 
 	
 	44Z@@r  c                    d}|j                   %| j                  j                  |      }||d|z  z  }|d| j                  j	                  |j
                  dd      z  z  }|| j                  |      z  }|S r  r  r  s        r  r  z)DDLCompiler.visit_column_check_constraintz  r  r  c                B    t        |      dk(  ryd}|j                  % j                  j                  |      }||d|z  z  }|dz  }|ddj	                   fd|j
                  r|j                  n|j                  D              z  z  }| j                  |      z  }|S )Nr   r  r  zPRIMARY KEY r   r   c              3  h   K   | ])  }j                   j                  |j                         + y wr  r  r  r   r9  r  r  s     r  r;  z;DDLCompiler.visit_primary_key_constraint.<locals>.<genexpr>  s3      #
(  MM'(   /2)	r  r   r  r  r   _implicit_generatedcolumns_autoinc_firstr  r  r  s   `    r  visit_primary_key_constraintz(DDLCompiler.visit_primary_key_constraint  s     z?a??&!]]<<ZHN)(>99 #
 11 00''(#
 
 
 	
 	44Z@@r  c           
        | j                   d}|j                  %| j                   j                  |      }||d|z  z  }t        |j                        d   j
                  j                  }|ddj                  fd|j                  D              d| j                  ||      ddj                  fd	|j                  D              d
z  }|| j                  |      z  }|| j                  |      z  }|| j                  |      z  }|S )Nr  r  r   zFOREIGN KEY(r   c              3  h   K   | ])  }j                  |j                  j                         + y wr  )r  parentr   r9  r  r  s     r  r;  z;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>  '      7J!qxx}}-7Jr  z) REFERENCES r  c              3  h   K   | ])  }j                  |j                  j                         + y wr  )r  r   r   r  s     r  r;  z;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>  r  r  r'  )r  r   r  r  r   r   r   r   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_constraint  s   ==??&!]]<<ZHN)(>99J//03::@@II 7A7J7J  //L( II 7A7J7J 

 
	
 	,,Z88//
;;44Z@@r  c                $    |j                  |      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_table  s     $$U++r  c                    t        |      dk(  ryd}|j                  % j                  j                  |      }||d|z  z  }|d  j                  |fi |ddj                   fd|D              dz  }| j                  |      z  }|S )	Nr   r  r  rz  r&  r   c              3  h   K   | ])  }j                   j                  |j                         + y wr  r  r  s     r  r;  z6DDLCompiler.visit_unique_constraint.<locals>.<genexpr>  s%     F:admm))!&&1:r  r'  )r  r   r  r  !define_unique_constraint_distinctr   r  r  s   `    r  visit_unique_constraintz#DDLCompiler.visit_unique_constraint  s     z?a??&!]]<<ZHN)(>992D22:DDIIF:FF
 	
 	44Z@@r  c                     yr  r  r  s      r  r  z-DDLCompiler.define_unique_constraint_distinct  s     r  c                    d}|j                   || j                  |      z  }|j                  || j                  |      z  }|S r  )ondelete"define_constraint_ondelete_cascadeonupdate"define_constraint_onupdate_cascader  r   r  s      r  r  z&DDLCompiler.define_constraint_cascades  sP     *D;;JGGD*D;;JGGDr  c                \    d| j                   j                  |j                  t              z  S )Nz ON DELETE %s)r  validate_sql_phraser  FK_ON_DELETEr  r   s     r  r  z.DDLCompiler.define_constraint_ondelete_cascade  -     !B!B"
 
 	
r  c                \    d| j                   j                  |j                  t              z  S )Nz ON UPDATE %s)r  r  r  FK_ON_UPDATEr  s     r  r  z.DDLCompiler.define_constraint_onupdate_cascade  r  r  c                    d}|j                   |j                   r|dz  }n|dz  }|j                  0|d| j                  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  sq      ,$$%))+Odmm&G&G$$l'  D r  c                F    d}|j                   |d|j                   z  z  }|S )Nr  z	 MATCH %s)r  r  s      r  r  z#DDLCompiler.define_constraint_match  s-    'K*"2"222Dr  c                    d| j                   j                  |j                  dd      z  }|j                  du r|dz  }|S |j                  du r|dz  }|S )NzGENERATED ALWAYS AS (%s)FTr  z STOREDz VIRTUAL)r  r  r[  	persisted)r  	generatedr  r  s       r  visit_computed_columnz!DDLCompiler.visit_computed_column  sr    )D,=,=,E,EU$ -F -
 
 $&ID    E)JDr  c                d    d|j                   rdndd}| j                  |      }|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  s@     H\9
 ++H5Gg%%Dr  )...)
r  rk   r/  r=   r  r  r  r&  r  r  r  r  r  r  r  )r~  rQ   r  r  )FT)r~  rQ   r|  r&  r  r   )r   zColumn[Any]r  rH  )r   zUnion[Visitable, str]r  r   )r   rR   r  r   r  r   )r   rT   r  r   r  r   )r   rP   r  r   )r   rO   r  r   )7r  r  r  r  r   r  r&   r  r  r  r8  r  rA  rF  rN  r_  rf  rX  rr  rv  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rd  rU  rZ  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r4  r4    s;   F FI,/03		 ,	 #C		
 &*	 .	 

 

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




B@(B
&6J;

.69	,0,
*25	"*25	
	.			
.
	

.
	
r  r4  c                     e Zd Zd1dZd2dZ	 	 	 	 	 	 d3dZd4dZd5dZd6dZd7dZ	d8dZ
d9d	Zd:d
Zd;dZd<dZd=dZd>dZd?dZ	 	 	 	 	 	 	 	 d@dZdAdZdBdZdCdZdDdZd?dZdEdZdFdZdGdZdHdZdIdZdEdZ	 	 	 	 	 	 dFdZdIdZd=dZ d;dZ!d<d Z"d9d!Z#	 	 	 	 	 	 d8d"Z$d7d#Z%d4d$Z&d1d%Z'd2d&Z(d5d'Z)dCd(Z*dJd)Z+d?d*Z,	 	 	 	 	 	 dKd+Z-dLd,Z.d- Z/	 	 	 	 	 	 dMd.Z0	 	 	 	 	 	 dNd/Z1y0)OGenericTypeCompilerc                     y)NFLOATr  r  s      r  visit_FLOATzGenericTypeCompiler.visit_FLOAT      r  c                     y)NDOUBLEr  r  s      r  visit_DOUBLEz GenericTypeCompiler.visit_DOUBLE      r  c                     y)NzDOUBLE PRECISIONr  r  s      r  visit_DOUBLE_PRECISIONz*GenericTypeCompiler.visit_DOUBLE_PRECISION  s     "r  c                     y)NREALr  r  s      r  
visit_REALzGenericTypeCompiler.visit_REAL  r  r  c                    |j                   y|j                  dd|j                   iz  S d|j                   |j                  dz  S )NNUMERICzNUMERIC(%(precision)s)	precisionz!NUMERIC(%(precision)s, %(scale)s)r  scaler  r  s      r  visit_NUMERICz!GenericTypeCompiler.visit_NUMERIC  M    ??"[[ +{EOO.LLL6"__:  r  c                    |j                   y|j                  dd|j                   iz  S d|j                   |j                  dz  S )NDECIMALzDECIMAL(%(precision)s)r  z!DECIMAL(%(precision)s, %(scale)s)r  r  r  s      r  visit_DECIMALz!GenericTypeCompiler.visit_DECIMAL)  r  r  c                     y)NINTEGERr  r  s      r  visit_INTEGERz!GenericTypeCompiler.visit_INTEGER4      r  c                     y)NSMALLINTr  r  s      r  visit_SMALLINTz"GenericTypeCompiler.visit_SMALLINT7      r  c                     y)NBIGINTr  r  s      r  visit_BIGINTz GenericTypeCompiler.visit_BIGINT:  r  r  c                     y)N	TIMESTAMPr  r  s      r  visit_TIMESTAMPz#GenericTypeCompiler.visit_TIMESTAMP=  s    r  c                     y)NDATETIMEr  r  s      r  visit_DATETIMEz"GenericTypeCompiler.visit_DATETIME@  r$  r  c                     y)NDATEr  r  s      r  
visit_DATEzGenericTypeCompiler.visit_DATEC  r  r  c                     y)NTIMEr  r  s      r  
visit_TIMEzGenericTypeCompiler.visit_TIMEF  r  r  c                     y)NCLOBr  r  s      r  
visit_CLOBzGenericTypeCompiler.visit_CLOBI  r  r  c                     y)NNCLOBr  r  s      r  visit_NCLOBzGenericTypeCompiler.visit_NCLOBL  r	  r  c                6    |}|r	|d| dz  }|r	|d| dz  }|S )Nr&  r'  z
 COLLATE "r  r  )r  r   lengthr  r  s        r  _render_string_typez'GenericTypeCompiler._render_string_typeO  s9     axqM!Dj1--Dr  c                P    | j                  d|j                  |j                        S )NCHARr<  r;  r  r  s      r  
visit_CHARzGenericTypeCompiler.visit_CHARY      ''eooNNr  c                P    | j                  d|j                  |j                        S )NNCHARr?  r  s      r  visit_NCHARzGenericTypeCompiler.visit_NCHAR\  s    ''uOOr  c                P    | j                  d|j                  |j                        S )NVARCHARr?  r  s      r  visit_VARCHARz!GenericTypeCompiler.visit_VARCHAR_  s$    ''u||U__
 	
r  c                P    | j                  d|j                  |j                        S )NNVARCHARr?  r  s      r  visit_NVARCHARz"GenericTypeCompiler.visit_NVARCHARd  s$    ''eoo
 	
r  c                P    | j                  d|j                  |j                        S )NTEXTr?  r  s      r  
visit_TEXTzGenericTypeCompiler.visit_TEXTi  rA  r  c                     y)NUUIDr  r  s      r  
visit_UUIDzGenericTypeCompiler.visit_UUIDl  r  r  c                     y)NBLOBr  r  s      r  
visit_BLOBzGenericTypeCompiler.visit_BLOBo  r  r  c                J    d|j                   xr d|j                   z  xs dz   S )NBINARY(%d)r  r;  r  s      r  visit_BINARYz GenericTypeCompiler.visit_BINARYr  s$    5<<AFU\\,AGRHHr  c                J    d|j                   xr d|j                   z  xs dz   S )N	VARBINARYrV  r  rW  r  s      r  visit_VARBINARYz#GenericTypeCompiler.visit_VARBINARYu  s$    ellDv/DJKKr  c                     y)NBOOLEANr  r  s      r  visit_BOOLEANz!GenericTypeCompiler.visit_BOOLEANx  r   r  c                    |j                   r| j                  j                  s| j                  ddd       S  | j                  |fi |S )Nr>      )r;  r  )native_uuidr  supports_native_uuidr<  rP  r  s      r  
visit_uuidzGenericTypeCompiler.visit_uuid{  sE      (I(I++F2+NN"4??5/B//r  c                (     | j                   |fi |S r  )rS  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  )r3  r  s      r  
visit_timezGenericTypeCompiler.visit_time      tu+++r  c                (     | j                   |fi |S r  )r-  r  s      r  visit_datetimez"GenericTypeCompiler.visit_datetime  s    "t""5/B//r  c                (     | j                   |fi |S r  )r0  r  s      r  
visit_datezGenericTypeCompiler.visit_date  rl  r  c                (     | j                   |fi |S r  )r'  r  s      r  visit_big_integerz%GenericTypeCompiler.visit_big_integer       t  -"--r  c                (     | j                   |fi |S r  )r#  r  s      r  visit_small_integerz'GenericTypeCompiler.visit_small_integer  s     #t""5/B//r  c                (     | j                   |fi |S r  )r  r  s      r  visit_integerz!GenericTypeCompiler.visit_integer  ri  r  c                (     | j                   |fi |S r  )r  r  s      r  
visit_realzGenericTypeCompiler.visit_real  rl  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  )r  r  s      r  visit_doublez GenericTypeCompiler.visit_double  rs  r  c                (     | j                   |fi |S r  )r  r  s      r  visit_numericz!GenericTypeCompiler.visit_numeric  ri  r  c                (     | j                   |fi |S r  rG  r  s      r  visit_stringz GenericTypeCompiler.visit_string  ri  r  c                (     | j                   |fi |S r  r  r  s      r  visit_unicodez!GenericTypeCompiler.visit_unicode  ri  r  c                (     | j                   |fi |S r  rM  r  s      r  
visit_textzGenericTypeCompiler.visit_text  rl  r  c                (     | j                   |fi |S r  r  r  s      r  visit_unicode_textz&GenericTypeCompiler.visit_unicode_text  rf  r  c                (     | j                   |fi |S r  r  r  s      r  
visit_enumzGenericTypeCompiler.visit_enum  ri  r  c                2    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_null  s"    #%*+
 	
r  c                Z     | j                   |j                  | j                        fi |S r  )r  type_enginer  r  s      r  visit_type_decoratorz(GenericTypeCompiler.visit_type_decorator  s)     t||E--dll;BrBBr  c                &     |j                   di |S r  )get_col_specr  s      r  visit_user_definedz&GenericTypeCompiler.visit_user_defined  s     "u!!'B''r  N)r  zsqltypes.Float[Any]r  r   r  r   )r  zsqltypes.Double[Any]r  r   r  r   )r  zsqltypes.DOUBLE_PRECISION[Any]r  r   r  r   )r  zsqltypes.REAL[Any]r  r   r  r   )r  zsqltypes.Numeric[Any]r  r   r  r   )r  zsqltypes.DECIMAL[Any]r  r   r  r   )r  zsqltypes.Integerr  r   r  r   )r  zsqltypes.SmallIntegerr  r   r  r   )r  zsqltypes.BigIntegerr  r   r  r   )r  zsqltypes.TIMESTAMPr  r   r  r   )r  zsqltypes.DateTimer  r   r  r   )r  zsqltypes.Dater  r   r  r   )r  zsqltypes.Timer  r   r  r   )r  zsqltypes.CLOBr  r   r  r   )r  zsqltypes.Textr  r   r  r   )r   r   r;  r  r  rH  r  r   )r  zsqltypes.CHARr  r   r  r   )r  zsqltypes.NCHARr  r   r  r   )r  zsqltypes.Stringr  r   r  r   )r  zsqltypes.NVARCHARr  r   r  r   )r  zsqltypes.Uuid[Any]r  r   r  r   )r  zsqltypes.LargeBinaryr  r   r  r   )r  zsqltypes.BINARYr  r   r  r   )r  zsqltypes.VARBINARYr  r   r  r   )r  zsqltypes.Booleanr  r   r  r   )r  zsqltypes.Unicoder  r   r  r   )r  zsqltypes.UnicodeTextr  r   r  r   )r  zsqltypes.Enumr  r   r  r   )r  zTypeDecorator[Any]r  r   r  r   )r  zUserDefinedType[Any]r  r   r  r   )2r  r  r  r  r  r  r  r  r  r  r#  r'  r*  r-  r0  r3  r6  r9  r<  r@  rD  rG  rJ  rM  rP  rS  rX  r[  r^  rc  re  rh  rk  rn  rp  rr  ru  rw  ry  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r    s   "3";>"	"
		!.;H	OP



OIL0,),14,	,
/,0,.0*0250	0
/,-.///,,),14,	,
/
C'C/2C	C
()(14(	(r  r  c                  *    e Zd Zd Zd Zd Zd Zd Zy)StrSQLTypeCompilerc                r    	 |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.process  sN    	2!&!9!9 &d1b11  	4&4&&u333	4s    66c                R    |j                  d      r| j                  S t        |      )Nrk  )rk  r  r  )r  r:  s     r  __getattr__zStrSQLTypeCompiler.__getattr__  s%    >>(#&&& %%r  c                    |j                   j                  |j                   j                  j                         k(  r|j                   j                  S t        |      S r  )r  r  upperreprr  s      r  r  z!StrSQLTypeCompiler._visit_unknown  sA    ??##u'?'?'E'E'GG??+++;r  c                     yr  r  r  s      r  r  zStrSQLTypeCompiler.visit_null  r  r  c                `    	 |j                   } |di |S # t        $ r t        |      cY S w xY wr  )r  r  r  )r  r  r  r  s       r  r  z%StrSQLTypeCompiler.visit_user_defined  s=    	& --L  %"%%  	;	s    --N)r  r  r  r  r  r  r  r  r  r  r  r  r    s    2&&r  r  c                      e Zd ZddZy)_SchemaForObjectCallablec                     y r  r  )r  _SchemaForObjectCallable__objs     r  r  z!_SchemaForObjectCallable.__call__  s    3r  N)r  r   r  r   r  r  r  r  r  r    s    .r  r  c                      e Zd ZddZy)r(  c                     y r  r  )r  r  s     r  r  z _BindNameForColProtocol.__call__  s    sr  N)r  r  r  r   r  r  r  r  r(  r(    s    :r  r(  c                  h   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<   	 	 	 	 	 d+	 	 	 	 	 	 	 	 	 	 	 d,dZd Z	 	 	 	 	 	 d-dZd.dZd.dZd Zd.dZd/dZd Zd0d1dZd0d2dZd Z	 d3	 	 	 	 	 d4dZ	 d0	 	 	 	 	 d5dZ	 d0	 	 	 	 	 d6dZd0dZ ej@                  d      	 d3	 	 	 	 	 d7d       Z!	 d3	 	 	 	 	 d8d Z"	 d3	 	 	 	 	 d8d!Z#	 	 	 	 	 	 	 	 d9d"Z$d:d#Z%	 	 d;	 	 	 	 	 	 	 d<d$Z&d% Z'	 d0d&Z(	 	 	 	 	 d=	 	 	 	 	 	 	 	 	 	 	 	 	 d>d'Z)d3d(Z*ejV                  d)        Z,d?d*Z-y)@r  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_translateNc                    || _         || _        |xs | j                  | _        || _        | j                  dz  | _        || _        || _        i | _        | j                   j                  dv | _	        y)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.
        r1   )r   r   N)
r  r  r  escape_quoteescape_to_quoteomit_schemaquote_case_sensitive_collationsr  rj  r  )r  r  r  r  r  r  r  s          r  r  zIdentifierPreparer.__init__  st    . *&<$*<*<(#0014&/N, $ 7 7 <
 !
r  c                    | j                   j                  | j                         }|j                  j                  | j                         d |v fd}||_        |_        |S )Nc                    | j                   }| j                  r:|r6| d|v sd|v rt        j                  d|z        t	        d|xs 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_mapr2   r  r.   )r  r   includes_nones     r  symbol_getterz@IdentifierPreparer._with_schema_translate.<locals>.symbol_getter;  sw    ::D""(8M#t**8:>?  ##tw7u  zz!r  )r  __new__rv  rw  r  r  )r  r  prepr  r  s       @r  r  z)IdentifierPreparer._with_schema_translate5  sX    ~~%%dnn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                    | j                  d      }|v r|   }n|dv rt        j                  d      |}|s-j                  j                  }|st        j
                  d      j                  |      S )Nr1   )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   r2   r<  r  default_schema_namer  r  )r  r   r  dr  s      r  r  z=IdentifierPreparer._render_schema_translates.<locals>.replace]  s    771:Dqy#$T7 ?*11=  $( ##'<<#C#C '**=  $$%566r  z(__\[SCHEMA_([^\]]+)\]))r  r2   r<  r]  r  )r  r/  r  r  r  s   `   @r  r  z,IdentifierPreparer._render_schema_translatesM  s\     !1977--9  4AgJ	72 vv0'9EEr  c                    |j                  | j                  | j                        }| j                  r|j                  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_identifierx  s>     d//1E1EF  MM#t,Er  c                N    |j                  | 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1143D3DEEr  c                x    |7|j                  |      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

        zUnexpected SQL phrase: z (matching against r'  )r  r2   r  r  )r  r  r`  s      r  r  z&IdentifierPreparer.validate_sql_phrase  s=     syy'9""CKK)  r  c                X    | j                   | 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_identifier  s3     %%e,-	
r  c                    |j                         }|| j                  v xs? |d   | j                  v xs, | j                  j	                  t        |             xs ||k7  S )z5Return True if the given identifier requires quoting.r   )rE  reserved_wordsillegal_initial_characterslegal_charactersr  r   )r  r  lc_values      r  ro  z#IdentifierPreparer._requires_quotes  sf    ;;=+++ #Qx4:::#((..s5z::# E!		
r  c                L    | j                   j                  t        |             S )zjReturn True if the given identifier requires quoting, but
        not taking case convention into account.)r  r  r   r  s     r  rH  z1IdentifierPreparer._requires_quotes_illegal_chars  s"     ((..s5z:::r  c                V    |t        j                  dd       | j                  |      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`.

        zThe 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.9r  )r&   r  r  )r  r#   forces      r  r  zIdentifierPreparer.quote_schema  s5    .    !  zz&!!r  c                R   |t        j                  dd       t        |dd      }|k|| j                  v r| j                  |   S | j	                  |      r| j                  |      | j                  |<   n|| j                  |<   | j                  |   S |r| j                  |      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  r  r  )r&   r  rD  r  ro  r  )r  r_  r  s      r  r  zIdentifierPreparer.quote  s    ,    !  w-=%}}U++((/+/+@+@+GDMM%(+0DMM%(}}U++((//Lr  c                @    | j                   r| j                  |      S |S r  )r  r  )r  collation_names     r  r  z#IdentifierPreparer.format_collation  s     //::n--!!r  c                    | j                  |j                        }| j                  |      }| j                  s|r|| j	                  |      dz   |z   }|S r  )r  r   r  r  r  )r  rN  r<  r   r  s        r  r#  z"IdentifierPreparer.format_sequence  s[     zz(--(11(;    ,$$%56<tCDr  c                @    | j                  |xs |j                        S r  r  r   )r  r  r   s      r  r  zIdentifierPreparer.format_label+  s     zz$,%**--r  c                f    ||J | j                  |j                        S | j                  |      S r  r  )r  r  r   s      r  rj  zIdentifierPreparer.format_alias0  s7     <$$$::ejj))::d##r  c                j    |xs |j                   }| j                  |      r| j                  |      }|S r  )r_  ro  r  )r  	savepointr   r_  s       r  r  z#IdentifierPreparer.format_savepoint9  s5     '	  '))%0Er  zsqlalchemy.sql.namingc                "   t         j                  j                  }|j                  t        u r|j                  ||j                        }|y |j                  }|J |j                  dk(  r| j                  ||      S | j                  ||      S )Nr~  )_alembic_quote)
r&   r#  
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_constraintB  s     **??j(44J,,D |??D$$/66^ 7   ;;^ <  r  c                    | j                   j                  xs | j                   j                  }| j                  |||      S r  )r  max_index_name_lengthro   _truncate_and_render_maxlen_namer  r   r  max_s       r  r  z1IdentifierPreparer.truncate_and_render_index_name\  sD     LL.. 2||11 	 44$
 	
r  c                    | j                   j                  xs | j                   j                  }| j                  |||      S r  )r  max_constraint_name_lengthro  r  r  s       r  r  z6IdentifierPreparer.truncate_and_render_constraint_namej  sD     LL33 2||11 	 44$
 	
r  c                    t        |t        j                        r3t        |      |kD  r@|d|dz
   dz   t	        j
                  |      dd  z   }n| j                  j                  |       |s|S | j                  |      S )Nr   rc  r$  )	r  r   rC   r  r&   md5_hexr  validate_identifierr  )r  r   r  r  s       r  r  z3IdentifierPreparer._truncate_and_render_maxlen_namex  ss     dH5564y4Aq)C/$,,t2DRS2IILL,,T2K::d##r  c                0    | j                  |      }|J |S r  )r  )r  r~  r   s      r  r  zIdentifierPreparer.format_index  s#    %%e,r  c                    |$t         rt        |t              sJ |j                  }| j	                  |      }| j                  |      }| j                  s|r|r| j                  |      dz   |z   }|S )z'Prepare a quoted table and schema name.r)  )r   r  rZ   r   r  r  r  r  )r  r   r<  r   rE  r  s         r  r  zIdentifierPreparer.format_table  sr     <!%999::DD!11%8J3C&&'783>GFr  c                $    | j                  |      S )zPrepare a quoted schema name.r  rH  s     r  rE  z IdentifierPreparer.format_schema  s     zz$r  c                ~    |+t        |t        j                        r|j                  |      }| j	                  |      S )Prepare a quoted column name.)r  r   rC   r?  r  )r  r   rp  s      r  r^  z$IdentifierPreparer.format_label_name  s;     J(++%
 >>(+Dzz$r  c                v   ||j                   }|J |+t        |t        j                        r|j	                  |      }t        |dd      sF|r3| j                  |j                  ||      dz   | j                  |      z   S | j                  |      S |r$| j                  |j                  ||      dz   |z   S |S )r  r  F)r<  r   r)  )	r   r  r   rC   r?  rD  r  r   r  )r  r   r  r   
table_namer<  rp  s          r  r  z IdentifierPreparer.format_column  s     <;;D###J(++%
 >>(+Dv|U3%%* &   jj&	' zz$''
 %%* &   	 r  c                    | j                  |      }| j                  s(|r&|r$| j                  |      | j                  |d      fS | j                  |d      fS )z(Format table name and schema as a tuple.Fr}  )r  r  r  r  )r  r   r<  r  s       r  r=  z#IdentifierPreparer.format_table_seq  sj      11%8J3C!!"23!!%E!: 
 %%e%>@@r  c                    d | j                   | j                  | j                  | j                        fD        \  }}}t        j                  d|||dz        }|S )Nc              3  F   K   | ]  }t        j                  |        y wr  )r]  r^  r  s     r  r;  z4IdentifierPreparer._r_identifiers.<locals>.<genexpr>  s$      )
 IIaLs   !zM(?:(?:%(initial)s((?:%(escaped)s|[^%(final)s])+)%(final)s|([^\.]+))(?=\.|$))+)initialfinalr  )r  r  r  r]  r_  )r  r  r  escaped_finalrs        r  _r_identifiersz!IdentifierPreparer._r_identifiers  sp    )
 ""  ''(8(89)
% JJ$ "EmLM
 r  c                    | j                   }|j                  |      D cg c]  \  }}|xs | c}}D cg c]  }| j                  |       c}S c c}}w c c}w )z:Unpack 'schema.table.column'-like strings into components.)r  findallr  )r  identifiersr  ar}  r  s         r  unformat_identifiersz'IdentifierPreparer.unformat_identifiers  sh      *+;)?@)?Aaf1f)?@
@ %%a(@
 	
@
s
   AA)r  Nr  TF)r  rk   r  r   r  rH  r  r   r  r&  r  r&  )r/  r   r  rl   r  r   )r  r   r  r   )r  r   r  r&  r  )r#   r   r  r   r  r   )r_  r   r  r   r  r   )T)rN  zschema.Sequencer<  r&  r  r   )r  z
Label[Any]r   rH  r  r   )r  zOptional[AliasedReturnsRows]r   rH  r  r   )r   zUnion[Constraint, Index]r  r&  r  rH  )r   r   r  r&  r  r   )r   r   r  rI  r  r&  r  r   )r~  rQ   r  r   )TN)r   rY   r<  r&  r   rH  r  r   )FNNFN)r   zColumnElement[Any]r  r&  r   rH  r  rH  r<  r&  rp  zOptional[Mapping[str, Any]]r  r   )r  r   r  zSequence[str]).r  r  r  r	  RESERVED_WORDSr  LEGAL_CHARACTERSr  ILLEGAL_INITIAL_CHARACTERSr  r
  r@  
attrgetterr  r  r  r  r  r  r  r  r  ro  rH  r  r  r  r#  r  rj  r  r&   r	  r  r  r  r  r  r  rE  r^  r  r=  r  r  r  r  r  r  r  r    s   J#N'!;&&2E(2E2Eh2O/O -2#T1
 !%)04!"
"
 "
 #	"

 "
 *."
 "
H0)F)F4J)F	)FV
F$

;
%"N2h" =A'59	  8<..'4.	. JN$1$9F$	$ T01KO2DH	 24 15

)-
	
 15

)-
	
$$"$48$	$  "	  	
 
(   "  "$( 04,", , 	,
 ", , ., 
,\A" 
 "
r  r  )r	  
__future__r   r  collections.abcabcr  r  enumr   rp  r  r@  r]  timer   rM  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&   r8  _typingr'   r(   r)   r*   r+   r,   r-   r.   r/   visitorsr0   r2   r3   util.typingr4   r5   r6   r7   
annotationr8   r9   r:   r;   r  r<   r>  r=   dmlr>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   type_apir^   r_   r`   ra   rb   engine.cursorrc   engine.interfacesrd   re   rf   rg   rh   ri   rj   rk   rl   r   _FromHintsTyper  r_  Ir  LEGAL_CHARACTERS_PLUS_SPACErt  r   r  r  r  r  UNICODEr  r  rl  rm  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  r"  r  r  r/  r0  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
  r  _CompoundSelectKeywordr   	UNION_ALLr   
EXCEPT_ALLr   INTERSECT_ALLr   r   r  r  r  r  r  r  r$  r.  rD  rT  ra  ro  rt  r=  ru  rv  rw  rx  
namedtuplerz  r  EnsureKWArgr  BinaryElementRoleCompilerColumnElementr   r  r  r  r4  r  r  r  r(  r  )r  s   0r  <module>r9	     s3  " #  )      	             !                       &     2  !  %    ! "  #	+," #)#**''&' #",,(1./&+'"','$)#4<:<=3=C+: lC'(_B 2::.5 (bjj):BDDA .3Arl;lc!fl;AA3%H rzz<bdd rzz<bdd rzz5rtt<bjjA2::N"**92::F$ "$.NNG. MM6. MM5	.
 MM5. MM5. MM5. MM3. LL%. LL&. LL&. LL%. LL&. LL%.  4.  ""$<!." #.$ 	%.& M'.( OOV).* +., -.. OOX/.0 MM61.2 MM63.4 j5.6 {7.: i;.< ;=.> MM6?.@ fA.B fC.F wG.H fI.J nK.L ]eUec[.	b 
NN!4N.hyNNNFNNFh_-	) & ""$(& %%++W%%//%%,,h%%00,%%//%%33_  >   ! *   
J  i $1 $:J :zt
 tnZ 2!; !$G  g . FKF B
&l
?#'''w6HI ?#DI' I'XF4## F0	C ("@"@2#
	C ("@"@#
LSU
( SU
ljl
[ l
^m( m`z(, z(z&, &B/x /;h ;U
 U
_ <s   =c&