zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
U
¸ý°d´@ã@stddlmZddlmZddlmZddlmZddlmZddlm    Z    dd    l
m Z dd
l
m Z dd l
m Z dd l
mZdd l
mZddl
mZddlmZddlmZddlmZededZerÐddlmZGdd„de jƒZGdd„deƒZdd„ZGdd„dejeƒZGdd„deƒZGdd „d eƒZ Gd!d"„d"eƒZ!Gd#d$„d$eƒZ"Gd%d&„d&eƒZ#Gd'd(„d(eƒZ$d)S)*é)Ú annotations)ÚAny)Ú TYPE_CHECKING)ÚTypeVaré)Útypes)ÚARRAYé)Ú    coercions)Úelements)Ú
expression)Ú    functions)Úroles)Úschema)ÚColumnCollectionConstraint)ÚTEXT)ÚInternalTraversalÚ_T)Úbound)Ú_TraverseInternalsTypec@sreZdZUdZdZdZdejfdejfdejfgZ    de
d<dd    „Z dd d „Z d d„Z ejfdd„Zedd„ƒZd
S)Úaggregate_order_byaàRepresent a PostgreSQL aggregate order by expression.
 
    E.g.::
 
        from sqlalchemy.dialects.postgresql import aggregate_order_by
        expr = func.array_agg(aggregate_order_by(table.c.a, table.c.b.desc()))
        stmt = select(expr)
 
    would represent the expression::
 
        SELECT array_agg(a ORDER BY b DESC) FROM table;
 
    Similarly::
 
        expr = func.string_agg(
            table.c.a,
            aggregate_order_by(literal_column("','"), table.c.a)
        )
        stmt = select(expr)
 
    Would represent::
 
        SELECT string_agg(a, ',' ORDER BY a) FROM table;
 
    .. versionchanged:: 1.2.13 - the ORDER BY argument may be multiple terms
 
    .. seealso::
 
        :class:`_functions.array_agg`
 
    Ú
postgresqlÚtargetÚtypeÚorder_byrÚ_traverse_internalscGsjt tj|¡|_|jj|_t|ƒ}|dkr4tdƒ‚n2|dkrRt tj|d¡|_nt    j
|dtjiŽ|_dS)Nrz)at least one ORDER BY element is requiredrZ_literal_as_text_role) r
ÚexpectrÚExpressionElementRolerrÚlenÚ    TypeErrorrr Z
ClauseList)ÚselfrrZ_lob©r!úYd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/dialects/postgresql/ext.pyÚ__init__Js
 
ÿÿÿzaggregate_order_by.__init__NcCs|S©Nr!)r Zagainstr!r!r"Ú
self_groupZszaggregate_order_by.self_groupcKs |j|jfSr$©rr)r Úkwargsr!r!r"Ú get_children]szaggregate_order_by.get_childrencKs$||jf|Ž|_||jf|Ž|_dSr$r&)r ÚcloneÚkwr!r!r"Ú_copy_internals`sz"aggregate_order_by._copy_internalscCs|jj|jjSr$)rÚ _from_objectsr©r r!r!r"r,dsz aggregate_order_by._from_objects)N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__Ú__visit_name__Zstringify_dialectrZdp_clauseelementZdp_typerÚ__annotations__r#r%r(r Z_cloner+Úpropertyr,r!r!r!r"r s
 ý 
rcsPeZdZdZdZdZdZdZe     ddd¡d    d
„ƒZ
‡fd d „Z dd d„Z ‡Z S)ÚExcludeConstraintzäA table-level EXCLUDE constraint.
 
    Defines an EXCLUDE constraint as described in the `PostgreSQL
    documentation`__.
 
    __ https://www.postgresql.org/docs/current/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE
 
    Zexclude_constraintNFrÚwherez:class:`.ExcludeConstraint`z$:paramref:`.ExcludeConstraint.where`cOsúg}g}i|_t|Ž\}}tt tj|¡|ƒD]V\\}}}    }
} |
dk    rP| |
¡|dk    r^|jn|    } | dk    rt| |j| <| || | f¡q.||_t    j
|f|ž|  d¡|  d¡|  d¡dœŽ|  dd¡|_ |  d¡} | dk    rèt  tj| ¡|_|  d    i¡|_dS)
a
        Create an :class:`.ExcludeConstraint` object.
 
        E.g.::
 
            const = ExcludeConstraint(
                (Column('period'), '&&'),
                (Column('group'), '='),
                where=(Column('group') != 'some group'),
                ops={'group': 'my_operator_class'}
            )
 
        The constraint is normally embedded into the :class:`_schema.Table`
        construct
        directly, or added later using :meth:`.append_constraint`::
 
            some_table = Table(
                'some_table', metadata,
                Column('id', Integer, primary_key=True),
                Column('period', TSRANGE()),
                Column('group', String)
            )
 
            some_table.append_constraint(
                ExcludeConstraint(
                    (some_table.c.period, '&&'),
                    (some_table.c.group, '='),
                    where=some_table.c.group != 'some group',
                    name='some_table_excl_const',
                    ops={'group': 'my_operator_class'}
                )
            )
 
        :param \*elements:
 
          A sequence of two tuples of the form ``(column, operator)`` where
          "column" is either a :class:`_schema.Column` object, or a SQL
          expression element (e.g. ``func.int8range(table.from, table.to)``)
          or the name of a column as string, and "operator" is a string
          containing the operator to use (e.g. `"&&"` or `"="`).
 
          In order to specify a column name when a :class:`_schema.Column`
          object is not available, while ensuring
          that any necessary quoting rules take effect, an ad-hoc
          :class:`_schema.Column` or :func:`_expression.column`
          object should be used.
          The ``column`` may also be a string SQL expression when
          passed as :func:`_expression.literal_column` or
          :func:`_expression.text`
 
        :param name:
          Optional, the in-database name of this constraint.
 
        :param deferrable:
          Optional bool.  If set, emit DEFERRABLE or NOT DEFERRABLE when
          issuing DDL for this constraint.
 
        :param initially:
          Optional string.  If set, emit INITIALLY <value> when issuing DDL
          for this constraint.
 
        :param using:
          Optional string.  If set, emit USING <index_method> when issuing DDL
          for this constraint. Defaults to 'gist'.
 
        :param where:
          Optional SQL expression construct or literal SQL string.
          If set, emit WHERE <predicate> when issuing DDL
          for this constraint.
 
        :param ops:
          Optional dictionary.  Used to define operator classes for the
          elements; works the same way as that of the
          :ref:`postgresql_ops <postgresql_operator_classes>`
          parameter specified to the :class:`_schema.Index` construct.
 
          .. versionadded:: 1.3.21
 
          .. seealso::
 
            :ref:`postgresql_operator_classes` - general description of how
            PostgreSQL operator classes are specified.
 
        NÚnameÚ
deferrableÚ    initially)r7r8r9ÚusingZgistr6Úops)Ú    operatorsÚzipr
Z expect_col_expression_collectionrZDDLConstraintColumnRoleÚappendr7Ú _render_exprsrr#Úgetr:rZStatementOptionRoler6r;)r r r*ÚcolumnsZ render_exprsZ expressionsr<ÚexprÚcolumnZstrnameZ add_elementÚoperatorr7r6r!r!r"r#zs@Z ÿü
 
ÿþû
zExcludeConstraint.__init__c s&tƒ ˆ¡‡fdd„|jDƒ|_dS)Ncs0g|](\}}}t|tƒs|nˆj|||f‘qSr!)Ú
isinstanceÚstrÚc)Ú.0rBr7rD©Útabler!r"Ú
<listcomp>þs
üýz1ExcludeConstraint._set_parent.<locals>.<listcomp>)ÚsuperÚ _set_parentr?)r rJr*©Ú    __class__rIr"rMûs 
úzExcludeConstraint._set_parentc sJ‡‡fdd„ˆjDƒ}ˆj|ˆjˆjˆjˆjˆjdœŽ}|j ˆj¡|S)Ncs&g|]\}}}t |ˆjˆ¡|f‘qSr!)rZ_copy_expressionÚparent)rHrBÚ_rD©r Ú target_tabler!r"rKsýþz+ExcludeConstraint._copy.<locals>.<listcomp>)r7r8r9r6r:)    r?rOr7r8r9r6r:ÚdispatchÚ_update)r rSr*r rGr!rRr"Ú_copys ûúzExcludeConstraint._copy)N)r.r/r0r1r2r6Ú inherit_cacheZcreate_drop_stringify_dialectr Z_document_text_coercionr#rMrVÚ __classcell__r!r!rNr"r5is    ý
| r5cOst|d<tjj||ŽS)zÏPostgreSQL-specific form of :class:`_functions.array_agg`, ensures
    return type is :class:`_postgresql.ARRAY` and not
    the plain :class:`_types.ARRAY`, unless an explicit ``type_``
    is passed.
 
    Z_default_array_type)rr ÚfuncÚ    array_agg)Úargr*r!r!r"rZsrZcs eZdZdZ‡fdd„Z‡ZS)Ú _regconfig_fnTcsnt|ƒ}t|ƒdkrBtjtj| d¡tˆddƒˆtj    d}|g}ng}‡fdd„|Dƒ}t
ƒj |||ŽdS)Nrrr7)r7Úapply_propagate_attrsÚtype_c    s(g|] }tjtj|tˆddƒˆd‘qS©r7N)r7r]©r
rrrÚgetattr©rHrGr-r!r"rK8sú
üz*_regconfig_fn.__init__.<locals>.<listcomp>) Úlistrr
rrrÚpoprarÚ    REGCONFIGrLr#)r Úargsr'Ú initial_argÚ
addtl_argsrNr-r"r#)s 
û
ù    z_regconfig_fn.__init__)r.r/r0rWr#rXr!r!rNr"r\&sr\c@seZdZdZdZejZdS)Ú to_tsvectoraÇThe PostgreSQL ``to_tsvector`` SQL function.
 
    This function applies automatic casting of the REGCONFIG argument
    to use the :class:`_postgresql.REGCONFIG` datatype automatically,
    and applies a return type of :class:`_postgresql.TSVECTOR`.
 
    Assuming the PostgreSQL dialect has been imported, either by invoking
    ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL
    engine using ``create_engine("postgresql...")``,
    :class:`_postgresql.to_tsvector` will be used automatically when invoking
    ``sqlalchemy.func.to_tsvector()``, ensuring the correct argument and return
    type handlers are used at compile and execution time.
 
    .. versionadded:: 2.0.0rc1
 
    TN)r.r/r0r1rWrZTSVECTORrr!r!r!r"riDsric@seZdZdZdZejZdS)Ú
to_tsqueryaÃThe PostgreSQL ``to_tsquery`` SQL function.
 
    This function applies automatic casting of the REGCONFIG argument
    to use the :class:`_postgresql.REGCONFIG` datatype automatically,
    and applies a return type of :class:`_postgresql.TSQUERY`.
 
    Assuming the PostgreSQL dialect has been imported, either by invoking
    ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL
    engine using ``create_engine("postgresql...")``,
    :class:`_postgresql.to_tsquery` will be used automatically when invoking
    ``sqlalchemy.func.to_tsquery()``, ensuring the correct argument and return
    type handlers are used at compile and execution time.
 
    .. versionadded:: 2.0.0rc1
 
    TN©r.r/r0r1rWrÚTSQUERYrr!r!r!r"rjZsrjc@seZdZdZdZejZdS)Úplainto_tsqueryaÒThe PostgreSQL ``plainto_tsquery`` SQL function.
 
    This function applies automatic casting of the REGCONFIG argument
    to use the :class:`_postgresql.REGCONFIG` datatype automatically,
    and applies a return type of :class:`_postgresql.TSQUERY`.
 
    Assuming the PostgreSQL dialect has been imported, either by invoking
    ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL
    engine using ``create_engine("postgresql...")``,
    :class:`_postgresql.plainto_tsquery` will be used automatically when
    invoking ``sqlalchemy.func.plainto_tsquery()``, ensuring the correct
    argument and return type handlers are used at compile and execution time.
 
    .. versionadded:: 2.0.0rc1
 
    TNrkr!r!r!r"rmpsrmc@seZdZdZdZejZdS)Úphraseto_tsqueryaÕThe PostgreSQL ``phraseto_tsquery`` SQL function.
 
    This function applies automatic casting of the REGCONFIG argument
    to use the :class:`_postgresql.REGCONFIG` datatype automatically,
    and applies a return type of :class:`_postgresql.TSQUERY`.
 
    Assuming the PostgreSQL dialect has been imported, either by invoking
    ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL
    engine using ``create_engine("postgresql...")``,
    :class:`_postgresql.phraseto_tsquery` will be used automatically when
    invoking ``sqlalchemy.func.phraseto_tsquery()``, ensuring the correct
    argument and return type handlers are used at compile and execution time.
 
    .. versionadded:: 2.0.0rc1
 
    TNrkr!r!r!r"rn†srnc@seZdZdZdZejZdS)Úwebsearch_to_tsqueryaáThe PostgreSQL ``websearch_to_tsquery`` SQL function.
 
    This function applies automatic casting of the REGCONFIG argument
    to use the :class:`_postgresql.REGCONFIG` datatype automatically,
    and applies a return type of :class:`_postgresql.TSQUERY`.
 
    Assuming the PostgreSQL dialect has been imported, either by invoking
    ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL
    engine using ``create_engine("postgresql...")``,
    :class:`_postgresql.websearch_to_tsquery` will be used automatically when
    invoking ``sqlalchemy.func.websearch_to_tsquery()``, ensuring the correct
    argument and return type handlers are used at compile and execution time.
 
    .. versionadded:: 2.0.0rc1
 
    TNrkr!r!r!r"roœsrocs(eZdZdZdZeZ‡fdd„Z‡ZS)Ú ts_headlinea¾The PostgreSQL ``ts_headline`` SQL function.
 
    This function applies automatic casting of the REGCONFIG argument
    to use the :class:`_postgresql.REGCONFIG` datatype automatically,
    and applies a return type of :class:`_types.TEXT`.
 
    Assuming the PostgreSQL dialect has been imported, either by invoking
    ``from sqlalchemy.dialects import postgresql``, or by creating a PostgreSQL
    engine using ``create_engine("postgresql...")``,
    :class:`_postgresql.ts_headline` will be used automatically when invoking
    ``sqlalchemy.func.ts_headline()``, ensuring the correct argument and return
    type handlers are used at compile and execution time.
 
    .. versionadded:: 2.0.0rc1
 
    Tcs¤t|ƒ}t|ƒdkrd}n,t|dtjƒrB|djjtjkrBd}nd}|rxt    j
t j |  d¡ˆtˆddƒtjd}|g}ng}‡fdd    „|Dƒ}tƒj|||ŽdS)
NéFrTrr7)r]r7r^c    s(g|] }tjtj|tˆddƒˆd‘qSr_r`rbr-r!r"rKäsú
üz(ts_headline.__init__.<locals>.<listcomp>)rcrrEr Ú ColumnElementrZ_type_affinityrrlr
rrrrdrarerLr#)r rfr'Z has_regconfigrgrhrNr-r"r#Çs. ÿþ
û
ù    zts_headline.__init__)    r.r/r0r1rWrrr#rXr!r!rNr"rp²srpN)%Ú
__future__rÚtypingrrrÚrÚarrayrZsqlr
r r r rrZ
sql.schemarZ sql.sqltypesrZ sql.visitorsrrrrrrr5rZZGenericFunctionr\rirjrmrnrorpr!r!r!r"Ú<module>s8                 I3