Edit on GitHub

sqlglot expressions DML.

  1"""sqlglot expressions DML."""
  2
  3from __future__ import annotations
  4
  5import typing as t
  6
  7from sqlglot.helper import trait
  8from sqlglot.expressions.core import (
  9    Expr,
 10    Expression,
 11    _apply_builder,
 12    _apply_list_builder,
 13    maybe_copy,
 14    _apply_conjunction_builder,
 15)
 16from sqlglot.expressions.ddl import DDL
 17from sqlglot.expressions.query import (
 18    Table,
 19    Where,
 20    From,
 21    _apply_cte_builder,
 22)
 23
 24if t.TYPE_CHECKING:
 25    from typing_extensions import Self, Unpack
 26    from sqlglot.dialects.dialect import DialectType
 27    from sqlglot.expressions.core import ExpOrStr
 28    from sqlglot._typing import ParserNoDialectArgs
 29
 30
 31@trait
 32class DML(Expr):
 33    """Trait for data manipulation language statements."""
 34
 35    def returning(
 36        self,
 37        expression: ExpOrStr,
 38        dialect: DialectType = None,
 39        copy: bool = True,
 40        **opts: Unpack[ParserNoDialectArgs],
 41    ) -> Self:
 42        """
 43        Set the RETURNING expression. Not supported by all dialects.
 44
 45        Example:
 46            >>> Delete().delete("tbl").returning("*", dialect="postgres").sql()
 47            'DELETE FROM tbl RETURNING *'
 48
 49        Args:
 50            expression: the SQL code strings to parse.
 51                If an `Expr` instance is passed, it will be used as-is.
 52            dialect: the dialect used to parse the input expressions.
 53            copy: if `False`, modify this expression instance in-place.
 54            opts: other options to use to parse the input expressions.
 55
 56        Returns:
 57            Delete: the modified expression.
 58        """
 59        return _apply_builder(
 60            expression=expression,
 61            instance=self,
 62            arg="returning",
 63            prefix="RETURNING",
 64            dialect=dialect,
 65            copy=copy,
 66            into=Returning,
 67            **opts,
 68        )
 69
 70
 71class Delete(Expression, DML):
 72    arg_types = {
 73        "with_": False,
 74        "this": False,
 75        "using": False,
 76        "where": False,
 77        "returning": False,
 78        "order": False,
 79        "limit": False,
 80        "tables": False,  # Multiple-Table Syntax (MySQL)
 81        "cluster": False,  # Clickhouse
 82        "hint": False,
 83    }
 84
 85    def delete(
 86        self,
 87        table: ExpOrStr,
 88        dialect: DialectType = None,
 89        copy: bool = True,
 90        **opts: Unpack[ParserNoDialectArgs],
 91    ) -> Delete:
 92        """
 93        Create a DELETE expression or replace the table on an existing DELETE expression.
 94
 95        Example:
 96            >>> Delete().delete("tbl").sql()
 97            'DELETE FROM tbl'
 98
 99        Args:
100            table: the table from which to delete.
101            dialect: the dialect used to parse the input expression.
102            copy: if `False`, modify this expression instance in-place.
103            opts: other options to use to parse the input expressions.
104
105        Returns:
106            Delete: the modified expression.
107        """
108        return _apply_builder(
109            expression=table,
110            instance=self,
111            arg="this",
112            dialect=dialect,
113            into=Table,
114            copy=copy,
115            **opts,
116        )
117
118    def where(
119        self,
120        *expressions: ExpOrStr | None,
121        append: bool = True,
122        dialect: DialectType = None,
123        copy: bool = True,
124        **opts: Unpack[ParserNoDialectArgs],
125    ) -> Delete:
126        """
127        Append to or set the WHERE expressions.
128
129        Example:
130            >>> Delete().delete("tbl").where("x = 'a' OR x < 'b'").sql()
131            "DELETE FROM tbl WHERE x = 'a' OR x < 'b'"
132
133        Args:
134            *expressions: the SQL code strings to parse.
135                If an `Expr` instance is passed, it will be used as-is.
136                Multiple expressions are combined with an AND operator.
137            append: if `True`, AND the new expressions to any existing expression.
138                Otherwise, this resets the expression.
139            dialect: the dialect used to parse the input expressions.
140            copy: if `False`, modify this expression instance in-place.
141            opts: other options to use to parse the input expressions.
142
143        Returns:
144            Delete: the modified expression.
145        """
146        return _apply_conjunction_builder(
147            *expressions,
148            instance=self,
149            arg="where",
150            append=append,
151            into=Where,
152            dialect=dialect,
153            copy=copy,
154            **opts,
155        )
156
157
158class Export(Expression):
159    arg_types = {"this": True, "connection": False, "options": True}
160
161
162class CopyParameter(Expression):
163    arg_types = {"this": True, "expression": False, "expressions": False}
164
165
166class Copy(Expression, DML):
167    arg_types = {
168        "this": True,
169        "kind": True,
170        "files": False,
171        "credentials": False,
172        "format": False,
173        "params": False,
174    }
175
176
177class Credentials(Expression):
178    arg_types = {
179        "credentials": False,
180        "encryption": False,
181        "storage": False,
182        "iam_role": False,
183        "region": False,
184    }
185
186
187class Directory(Expression):
188    arg_types = {"this": True, "local": False, "row_format": False}
189
190
191class DirectoryStage(Expression):
192    pass
193
194
195class Insert(Expression, DDL, DML):
196    arg_types = {
197        "hint": False,
198        "with_": False,
199        "is_function": False,
200        "this": False,
201        "expression": False,
202        "conflict": False,
203        "returning": False,
204        "overwrite": False,
205        "exists": False,
206        "alternative": False,
207        "where": False,
208        "ignore": False,
209        "by_name": False,
210        "stored": False,
211        "partition": False,
212        "settings": False,
213        "source": False,
214        "default": False,
215    }
216
217    def with_(
218        self,
219        alias: ExpOrStr,
220        as_: ExpOrStr,
221        recursive: bool | None = None,
222        materialized: bool | None = None,
223        append: bool = True,
224        dialect: DialectType = None,
225        copy: bool = True,
226        **opts: Unpack[ParserNoDialectArgs],
227    ) -> Insert:
228        """
229        Append to or set the common table expressions.
230
231        Example:
232            >>> import sqlglot
233            >>> sqlglot.parse_one("INSERT INTO t SELECT x FROM cte").with_("cte", as_="SELECT * FROM tbl").sql()
234            'WITH cte AS (SELECT * FROM tbl) INSERT INTO t SELECT x FROM cte'
235
236        Args:
237            alias: the SQL code string to parse as the table name.
238                If an `Expr` instance is passed, this is used as-is.
239            as_: the SQL code string to parse as the table expression.
240                If an `Expr` instance is passed, it will be used as-is.
241            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
242            materialized: set the MATERIALIZED part of the expression.
243            append: if `True`, add to any existing expressions.
244                Otherwise, this resets the expressions.
245            dialect: the dialect used to parse the input expression.
246            copy: if `False`, modify this expression instance in-place.
247            opts: other options to use to parse the input expressions.
248
249        Returns:
250            The modified expression.
251        """
252        return _apply_cte_builder(
253            self,
254            alias,
255            as_,
256            recursive=recursive,
257            materialized=materialized,
258            append=append,
259            dialect=dialect,
260            copy=copy,
261            **opts,
262        )
263
264
265class OnConflict(Expression):
266    arg_types = {
267        "duplicate": False,
268        "expressions": False,
269        "action": False,
270        "conflict_keys": False,
271        "index_predicate": False,
272        "constraint": False,
273        "where": False,
274    }
275
276
277class Returning(Expression):
278    arg_types = {"expressions": True, "into": False}
279
280
281class LoadData(Expression):
282    arg_types = {
283        "this": True,
284        "local": False,
285        "overwrite": False,
286        "inpath": False,
287        "files": False,
288        "partition": False,
289        "input_format": False,
290        "serde": False,
291    }
292
293
294class Update(Expression, DML):
295    arg_types = {
296        "with_": False,
297        "this": False,
298        "expressions": False,
299        "from_": False,
300        "where": False,
301        "returning": False,
302        "order": False,
303        "limit": False,
304        "options": False,
305        "hint": False,
306    }
307
308    def table(
309        self,
310        expression: ExpOrStr,
311        dialect: DialectType = None,
312        copy: bool = True,
313        **opts: Unpack[ParserNoDialectArgs],
314    ) -> Update:
315        """
316        Set the table to update.
317
318        Example:
319            >>> Update().table("my_table").set_("x = 1").sql()
320            'UPDATE my_table SET x = 1'
321
322        Args:
323            expression : the SQL code strings to parse.
324                If a `Table` instance is passed, this is used as-is.
325                If another `Expr` instance is passed, it will be wrapped in a `Table`.
326            dialect: the dialect used to parse the input expression.
327            copy: if `False`, modify this expression instance in-place.
328            opts: other options to use to parse the input expressions.
329
330        Returns:
331            The modified Update expression.
332        """
333        return _apply_builder(
334            expression=expression,
335            instance=self,
336            arg="this",
337            into=Table,
338            prefix=None,
339            dialect=dialect,
340            copy=copy,
341            **opts,
342        )
343
344    def set_(
345        self,
346        *expressions: ExpOrStr,
347        append: bool = True,
348        dialect: DialectType = None,
349        copy: bool = True,
350        **opts: Unpack[ParserNoDialectArgs],
351    ) -> Update:
352        """
353        Append to or set the SET expressions.
354
355        Example:
356            >>> Update().table("my_table").set_("x = 1").sql()
357            'UPDATE my_table SET x = 1'
358
359        Args:
360            *expressions: the SQL code strings to parse.
361                If `Expr` instance(s) are passed, they will be used as-is.
362                Multiple expressions are combined with a comma.
363            append: if `True`, add the new expressions to any existing SET expressions.
364                Otherwise, this resets the expressions.
365            dialect: the dialect used to parse the input expressions.
366            copy: if `False`, modify this expression instance in-place.
367            opts: other options to use to parse the input expressions.
368        """
369        return _apply_list_builder(
370            *expressions,
371            instance=self,
372            arg="expressions",
373            append=append,
374            into=Expr,
375            prefix=None,
376            dialect=dialect,
377            copy=copy,
378            **opts,
379        )
380
381    def where(
382        self,
383        *expressions: ExpOrStr | None,
384        append: bool = True,
385        dialect: DialectType = None,
386        copy: bool = True,
387        **opts: Unpack[ParserNoDialectArgs],
388    ) -> Update:
389        """
390        Append to or set the WHERE expressions.
391
392        Example:
393            >>> Update().table("tbl").set_("x = 1").where("x = 'a' OR x < 'b'").sql()
394            "UPDATE tbl SET x = 1 WHERE x = 'a' OR x < 'b'"
395
396        Args:
397            *expressions: the SQL code strings to parse.
398                If an `Expr` instance is passed, it will be used as-is.
399                Multiple expressions are combined with an AND operator.
400            append: if `True`, AND the new expressions to any existing expression.
401                Otherwise, this resets the expression.
402            dialect: the dialect used to parse the input expressions.
403            copy: if `False`, modify this expression instance in-place.
404            opts: other options to use to parse the input expressions.
405
406        Returns:
407            Update: the modified expression.
408        """
409        return _apply_conjunction_builder(
410            *expressions,
411            instance=self,
412            arg="where",
413            append=append,
414            into=Where,
415            dialect=dialect,
416            copy=copy,
417            **opts,
418        )
419
420    def from_(
421        self,
422        expression: ExpOrStr | None = None,
423        dialect: DialectType = None,
424        copy: bool = True,
425        **opts: Unpack[ParserNoDialectArgs],
426    ) -> Update:
427        """
428        Set the FROM expression.
429
430        Example:
431            >>> Update().table("my_table").set_("x = 1").from_("baz").sql()
432            'UPDATE my_table SET x = 1 FROM baz'
433
434        Args:
435            expression : the SQL code strings to parse.
436                If a `From` instance is passed, this is used as-is.
437                If another `Expr` instance is passed, it will be wrapped in a `From`.
438                If nothing is passed in then a from is not applied to the expression
439            dialect: the dialect used to parse the input expression.
440            copy: if `False`, modify this expression instance in-place.
441            opts: other options to use to parse the input expressions.
442
443        Returns:
444            The modified Update expression.
445        """
446        if not expression:
447            return maybe_copy(self, copy)
448
449        return _apply_builder(
450            expression=expression,
451            instance=self,
452            arg="from_",
453            into=From,
454            prefix="FROM",
455            dialect=dialect,
456            copy=copy,
457            **opts,
458        )
459
460    def with_(
461        self,
462        alias: ExpOrStr,
463        as_: ExpOrStr,
464        recursive: bool | None = None,
465        materialized: bool | None = None,
466        append: bool = True,
467        dialect: DialectType = None,
468        copy: bool = True,
469        **opts: Unpack[ParserNoDialectArgs],
470    ) -> Update:
471        """
472        Append to or set the common table expressions.
473
474        Example:
475            >>> Update().table("my_table").set_("x = 1").from_("baz").with_("baz", "SELECT id FROM foo").sql()
476            'WITH baz AS (SELECT id FROM foo) UPDATE my_table SET x = 1 FROM baz'
477
478        Args:
479            alias: the SQL code string to parse as the table name.
480                If an `Expr` instance is passed, this is used as-is.
481            as_: the SQL code string to parse as the table expression.
482                If an `Expr` instance is passed, it will be used as-is.
483            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
484            materialized: set the MATERIALIZED part of the expression.
485            append: if `True`, add to any existing expressions.
486                Otherwise, this resets the expressions.
487            dialect: the dialect used to parse the input expression.
488            copy: if `False`, modify this expression instance in-place.
489            opts: other options to use to parse the input expressions.
490
491        Returns:
492            The modified expression.
493        """
494        return _apply_cte_builder(
495            self,
496            alias,
497            as_,
498            recursive=recursive,
499            materialized=materialized,
500            append=append,
501            dialect=dialect,
502            copy=copy,
503            **opts,
504        )
505
506
507class Merge(Expression, DML):
508    arg_types = {
509        "this": True,
510        "using": True,
511        "on": False,
512        "using_cond": False,
513        "whens": True,
514        "with_": False,
515        "returning": False,
516    }
517
518
519class When(Expression):
520    arg_types = {"matched": True, "source": False, "condition": False, "then": True}
521
522
523class Whens(Expression):
524    """Wraps around one or more WHEN [NOT] MATCHED [...] clauses."""
525
526    arg_types = {"expressions": True}
@trait
class DML(sqlglot.expressions.core.Expr):
32@trait
33class DML(Expr):
34    """Trait for data manipulation language statements."""
35
36    def returning(
37        self,
38        expression: ExpOrStr,
39        dialect: DialectType = None,
40        copy: bool = True,
41        **opts: Unpack[ParserNoDialectArgs],
42    ) -> Self:
43        """
44        Set the RETURNING expression. Not supported by all dialects.
45
46        Example:
47            >>> Delete().delete("tbl").returning("*", dialect="postgres").sql()
48            'DELETE FROM tbl RETURNING *'
49
50        Args:
51            expression: the SQL code strings to parse.
52                If an `Expr` instance is passed, it will be used as-is.
53            dialect: the dialect used to parse the input expressions.
54            copy: if `False`, modify this expression instance in-place.
55            opts: other options to use to parse the input expressions.
56
57        Returns:
58            Delete: the modified expression.
59        """
60        return _apply_builder(
61            expression=expression,
62            instance=self,
63            arg="returning",
64            prefix="RETURNING",
65            dialect=dialect,
66            copy=copy,
67            into=Returning,
68            **opts,
69        )

Trait for data manipulation language statements.

def returning( self, expression: Union[int, str, sqlglot.expressions.core.Expr], dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, copy: bool = True, **opts: typing_extensions.Unpack[sqlglot._typing.ParserNoDialectArgs]) -> typing_extensions.Self:
36    def returning(
37        self,
38        expression: ExpOrStr,
39        dialect: DialectType = None,
40        copy: bool = True,
41        **opts: Unpack[ParserNoDialectArgs],
42    ) -> Self:
43        """
44        Set the RETURNING expression. Not supported by all dialects.
45
46        Example:
47            >>> Delete().delete("tbl").returning("*", dialect="postgres").sql()
48            'DELETE FROM tbl RETURNING *'
49
50        Args:
51            expression: the SQL code strings to parse.
52                If an `Expr` instance is passed, it will be used as-is.
53            dialect: the dialect used to parse the input expressions.
54            copy: if `False`, modify this expression instance in-place.
55            opts: other options to use to parse the input expressions.
56
57        Returns:
58            Delete: the modified expression.
59        """
60        return _apply_builder(
61            expression=expression,
62            instance=self,
63            arg="returning",
64            prefix="RETURNING",
65            dialect=dialect,
66            copy=copy,
67            into=Returning,
68            **opts,
69        )

Set the RETURNING expression. Not supported by all dialects.

Example:
>>> Delete().delete("tbl").returning("*", dialect="postgres").sql()
'DELETE FROM tbl RETURNING *'
Arguments:
  • expression: the SQL code strings to parse. If an Expr instance is passed, it will be used as-is.
  • dialect: the dialect used to parse the input expressions.
  • copy: if False, modify this expression instance in-place.
  • opts: other options to use to parse the input expressions.
Returns:

Delete: the modified expression.

key: ClassVar[str] = 'dml'
required_args: 't.ClassVar[set[str]]' = {'this'}
class Delete(sqlglot.expressions.core.Expression, DML):
 72class Delete(Expression, DML):
 73    arg_types = {
 74        "with_": False,
 75        "this": False,
 76        "using": False,
 77        "where": False,
 78        "returning": False,
 79        "order": False,
 80        "limit": False,
 81        "tables": False,  # Multiple-Table Syntax (MySQL)
 82        "cluster": False,  # Clickhouse
 83        "hint": False,
 84    }
 85
 86    def delete(
 87        self,
 88        table: ExpOrStr,
 89        dialect: DialectType = None,
 90        copy: bool = True,
 91        **opts: Unpack[ParserNoDialectArgs],
 92    ) -> Delete:
 93        """
 94        Create a DELETE expression or replace the table on an existing DELETE expression.
 95
 96        Example:
 97            >>> Delete().delete("tbl").sql()
 98            'DELETE FROM tbl'
 99
100        Args:
101            table: the table from which to delete.
102            dialect: the dialect used to parse the input expression.
103            copy: if `False`, modify this expression instance in-place.
104            opts: other options to use to parse the input expressions.
105
106        Returns:
107            Delete: the modified expression.
108        """
109        return _apply_builder(
110            expression=table,
111            instance=self,
112            arg="this",
113            dialect=dialect,
114            into=Table,
115            copy=copy,
116            **opts,
117        )
118
119    def where(
120        self,
121        *expressions: ExpOrStr | None,
122        append: bool = True,
123        dialect: DialectType = None,
124        copy: bool = True,
125        **opts: Unpack[ParserNoDialectArgs],
126    ) -> Delete:
127        """
128        Append to or set the WHERE expressions.
129
130        Example:
131            >>> Delete().delete("tbl").where("x = 'a' OR x < 'b'").sql()
132            "DELETE FROM tbl WHERE x = 'a' OR x < 'b'"
133
134        Args:
135            *expressions: the SQL code strings to parse.
136                If an `Expr` instance is passed, it will be used as-is.
137                Multiple expressions are combined with an AND operator.
138            append: if `True`, AND the new expressions to any existing expression.
139                Otherwise, this resets the expression.
140            dialect: the dialect used to parse the input expressions.
141            copy: if `False`, modify this expression instance in-place.
142            opts: other options to use to parse the input expressions.
143
144        Returns:
145            Delete: the modified expression.
146        """
147        return _apply_conjunction_builder(
148            *expressions,
149            instance=self,
150            arg="where",
151            append=append,
152            into=Where,
153            dialect=dialect,
154            copy=copy,
155            **opts,
156        )
arg_types = {'with_': False, 'this': False, 'using': False, 'where': False, 'returning': False, 'order': False, 'limit': False, 'tables': False, 'cluster': False, 'hint': False}
def delete( self, table: Union[int, str, sqlglot.expressions.core.Expr], dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, copy: bool = True, **opts: typing_extensions.Unpack[sqlglot._typing.ParserNoDialectArgs]) -> Delete:
 86    def delete(
 87        self,
 88        table: ExpOrStr,
 89        dialect: DialectType = None,
 90        copy: bool = True,
 91        **opts: Unpack[ParserNoDialectArgs],
 92    ) -> Delete:
 93        """
 94        Create a DELETE expression or replace the table on an existing DELETE expression.
 95
 96        Example:
 97            >>> Delete().delete("tbl").sql()
 98            'DELETE FROM tbl'
 99
100        Args:
101            table: the table from which to delete.
102            dialect: the dialect used to parse the input expression.
103            copy: if `False`, modify this expression instance in-place.
104            opts: other options to use to parse the input expressions.
105
106        Returns:
107            Delete: the modified expression.
108        """
109        return _apply_builder(
110            expression=table,
111            instance=self,
112            arg="this",
113            dialect=dialect,
114            into=Table,
115            copy=copy,
116            **opts,
117        )

Create a DELETE expression or replace the table on an existing DELETE expression.

Example:
>>> Delete().delete("tbl").sql()
'DELETE FROM tbl'
Arguments:
  • table: the table from which to delete.
  • dialect: the dialect used to parse the input expression.
  • copy: if False, modify this expression instance in-place.
  • opts: other options to use to parse the input expressions.
Returns:

Delete: the modified expression.

def where( self, *expressions: Union[int, str, sqlglot.expressions.core.Expr, NoneType], append: bool = True, dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, copy: bool = True, **opts: typing_extensions.Unpack[sqlglot._typing.ParserNoDialectArgs]) -> Delete:
119    def where(
120        self,
121        *expressions: ExpOrStr | None,
122        append: bool = True,
123        dialect: DialectType = None,
124        copy: bool = True,
125        **opts: Unpack[ParserNoDialectArgs],
126    ) -> Delete:
127        """
128        Append to or set the WHERE expressions.
129
130        Example:
131            >>> Delete().delete("tbl").where("x = 'a' OR x < 'b'").sql()
132            "DELETE FROM tbl WHERE x = 'a' OR x < 'b'"
133
134        Args:
135            *expressions: the SQL code strings to parse.
136                If an `Expr` instance is passed, it will be used as-is.
137                Multiple expressions are combined with an AND operator.
138            append: if `True`, AND the new expressions to any existing expression.
139                Otherwise, this resets the expression.
140            dialect: the dialect used to parse the input expressions.
141            copy: if `False`, modify this expression instance in-place.
142            opts: other options to use to parse the input expressions.
143
144        Returns:
145            Delete: the modified expression.
146        """
147        return _apply_conjunction_builder(
148            *expressions,
149            instance=self,
150            arg="where",
151            append=append,
152            into=Where,
153            dialect=dialect,
154            copy=copy,
155            **opts,
156        )

Append to or set the WHERE expressions.

Example:
>>> Delete().delete("tbl").where("x = 'a' OR x < 'b'").sql()
"DELETE FROM tbl WHERE x = 'a' OR x < 'b'"
Arguments:
  • *expressions: the SQL code strings to parse. If an Expr instance is passed, it will be used as-is. Multiple expressions are combined with an AND operator.
  • append: if True, AND the new expressions to any existing expression. Otherwise, this resets the expression.
  • dialect: the dialect used to parse the input expressions.
  • copy: if False, modify this expression instance in-place.
  • opts: other options to use to parse the input expressions.
Returns:

Delete: the modified expression.

key: ClassVar[str] = 'delete'
required_args: 't.ClassVar[set[str]]' = set()
class Export(sqlglot.expressions.core.Expression):
159class Export(Expression):
160    arg_types = {"this": True, "connection": False, "options": True}
arg_types = {'this': True, 'connection': False, 'options': True}
key: ClassVar[str] = 'export'
required_args: 't.ClassVar[set[str]]' = {'options', 'this'}
class CopyParameter(sqlglot.expressions.core.Expression):
163class CopyParameter(Expression):
164    arg_types = {"this": True, "expression": False, "expressions": False}
arg_types = {'this': True, 'expression': False, 'expressions': False}
key: ClassVar[str] = 'copyparameter'
required_args: 't.ClassVar[set[str]]' = {'this'}
class Copy(sqlglot.expressions.core.Expression, DML):
167class Copy(Expression, DML):
168    arg_types = {
169        "this": True,
170        "kind": True,
171        "files": False,
172        "credentials": False,
173        "format": False,
174        "params": False,
175    }
arg_types = {'this': True, 'kind': True, 'files': False, 'credentials': False, 'format': False, 'params': False}
key: ClassVar[str] = 'copy'
required_args: 't.ClassVar[set[str]]' = {'kind', 'this'}
class Credentials(sqlglot.expressions.core.Expression):
178class Credentials(Expression):
179    arg_types = {
180        "credentials": False,
181        "encryption": False,
182        "storage": False,
183        "iam_role": False,
184        "region": False,
185    }
arg_types = {'credentials': False, 'encryption': False, 'storage': False, 'iam_role': False, 'region': False}
key: ClassVar[str] = 'credentials'
required_args: 't.ClassVar[set[str]]' = set()
class Directory(sqlglot.expressions.core.Expression):
188class Directory(Expression):
189    arg_types = {"this": True, "local": False, "row_format": False}
arg_types = {'this': True, 'local': False, 'row_format': False}
key: ClassVar[str] = 'directory'
required_args: 't.ClassVar[set[str]]' = {'this'}
class DirectoryStage(sqlglot.expressions.core.Expression):
192class DirectoryStage(Expression):
193    pass
key: ClassVar[str] = 'directorystage'
required_args: 't.ClassVar[set[str]]' = {'this'}
196class Insert(Expression, DDL, DML):
197    arg_types = {
198        "hint": False,
199        "with_": False,
200        "is_function": False,
201        "this": False,
202        "expression": False,
203        "conflict": False,
204        "returning": False,
205        "overwrite": False,
206        "exists": False,
207        "alternative": False,
208        "where": False,
209        "ignore": False,
210        "by_name": False,
211        "stored": False,
212        "partition": False,
213        "settings": False,
214        "source": False,
215        "default": False,
216    }
217
218    def with_(
219        self,
220        alias: ExpOrStr,
221        as_: ExpOrStr,
222        recursive: bool | None = None,
223        materialized: bool | None = None,
224        append: bool = True,
225        dialect: DialectType = None,
226        copy: bool = True,
227        **opts: Unpack[ParserNoDialectArgs],
228    ) -> Insert:
229        """
230        Append to or set the common table expressions.
231
232        Example:
233            >>> import sqlglot
234            >>> sqlglot.parse_one("INSERT INTO t SELECT x FROM cte").with_("cte", as_="SELECT * FROM tbl").sql()
235            'WITH cte AS (SELECT * FROM tbl) INSERT INTO t SELECT x FROM cte'
236
237        Args:
238            alias: the SQL code string to parse as the table name.
239                If an `Expr` instance is passed, this is used as-is.
240            as_: the SQL code string to parse as the table expression.
241                If an `Expr` instance is passed, it will be used as-is.
242            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
243            materialized: set the MATERIALIZED part of the expression.
244            append: if `True`, add to any existing expressions.
245                Otherwise, this resets the expressions.
246            dialect: the dialect used to parse the input expression.
247            copy: if `False`, modify this expression instance in-place.
248            opts: other options to use to parse the input expressions.
249
250        Returns:
251            The modified expression.
252        """
253        return _apply_cte_builder(
254            self,
255            alias,
256            as_,
257            recursive=recursive,
258            materialized=materialized,
259            append=append,
260            dialect=dialect,
261            copy=copy,
262            **opts,
263        )
arg_types = {'hint': False, 'with_': False, 'is_function': False, 'this': False, 'expression': False, 'conflict': False, 'returning': False, 'overwrite': False, 'exists': False, 'alternative': False, 'where': False, 'ignore': False, 'by_name': False, 'stored': False, 'partition': False, 'settings': False, 'source': False, 'default': False}
def with_( self, alias: Union[int, str, sqlglot.expressions.core.Expr], as_: Union[int, str, sqlglot.expressions.core.Expr], recursive: bool | None = None, materialized: bool | None = None, append: bool = True, dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, copy: bool = True, **opts: typing_extensions.Unpack[sqlglot._typing.ParserNoDialectArgs]) -> Insert:
218    def with_(
219        self,
220        alias: ExpOrStr,
221        as_: ExpOrStr,
222        recursive: bool | None = None,
223        materialized: bool | None = None,
224        append: bool = True,
225        dialect: DialectType = None,
226        copy: bool = True,
227        **opts: Unpack[ParserNoDialectArgs],
228    ) -> Insert:
229        """
230        Append to or set the common table expressions.
231
232        Example:
233            >>> import sqlglot
234            >>> sqlglot.parse_one("INSERT INTO t SELECT x FROM cte").with_("cte", as_="SELECT * FROM tbl").sql()
235            'WITH cte AS (SELECT * FROM tbl) INSERT INTO t SELECT x FROM cte'
236
237        Args:
238            alias: the SQL code string to parse as the table name.
239                If an `Expr` instance is passed, this is used as-is.
240            as_: the SQL code string to parse as the table expression.
241                If an `Expr` instance is passed, it will be used as-is.
242            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
243            materialized: set the MATERIALIZED part of the expression.
244            append: if `True`, add to any existing expressions.
245                Otherwise, this resets the expressions.
246            dialect: the dialect used to parse the input expression.
247            copy: if `False`, modify this expression instance in-place.
248            opts: other options to use to parse the input expressions.
249
250        Returns:
251            The modified expression.
252        """
253        return _apply_cte_builder(
254            self,
255            alias,
256            as_,
257            recursive=recursive,
258            materialized=materialized,
259            append=append,
260            dialect=dialect,
261            copy=copy,
262            **opts,
263        )

Append to or set the common table expressions.

Example:
>>> import sqlglot
>>> sqlglot.parse_one("INSERT INTO t SELECT x FROM cte").with_("cte", as_="SELECT * FROM tbl").sql()
'WITH cte AS (SELECT * FROM tbl) INSERT INTO t SELECT x FROM cte'
Arguments:
  • alias: the SQL code string to parse as the table name. If an Expr instance is passed, this is used as-is.
  • as_: the SQL code string to parse as the table expression. If an Expr instance is passed, it will be used as-is.
  • recursive: set the RECURSIVE part of the expression. Defaults to False.
  • materialized: set the MATERIALIZED part of the expression.
  • append: if True, add to any existing expressions. Otherwise, this resets the expressions.
  • dialect: the dialect used to parse the input expression.
  • copy: if False, modify this expression instance in-place.
  • opts: other options to use to parse the input expressions.
Returns:

The modified expression.

key: ClassVar[str] = 'insert'
required_args: 't.ClassVar[set[str]]' = set()
class OnConflict(sqlglot.expressions.core.Expression):
266class OnConflict(Expression):
267    arg_types = {
268        "duplicate": False,
269        "expressions": False,
270        "action": False,
271        "conflict_keys": False,
272        "index_predicate": False,
273        "constraint": False,
274        "where": False,
275    }
arg_types = {'duplicate': False, 'expressions': False, 'action': False, 'conflict_keys': False, 'index_predicate': False, 'constraint': False, 'where': False}
key: ClassVar[str] = 'onconflict'
required_args: 't.ClassVar[set[str]]' = set()
class Returning(sqlglot.expressions.core.Expression):
278class Returning(Expression):
279    arg_types = {"expressions": True, "into": False}
arg_types = {'expressions': True, 'into': False}
key: ClassVar[str] = 'returning'
required_args: 't.ClassVar[set[str]]' = {'expressions'}
class LoadData(sqlglot.expressions.core.Expression):
282class LoadData(Expression):
283    arg_types = {
284        "this": True,
285        "local": False,
286        "overwrite": False,
287        "inpath": False,
288        "files": False,
289        "partition": False,
290        "input_format": False,
291        "serde": False,
292    }
arg_types = {'this': True, 'local': False, 'overwrite': False, 'inpath': False, 'files': False, 'partition': False, 'input_format': False, 'serde': False}
key: ClassVar[str] = 'loaddata'
required_args: 't.ClassVar[set[str]]' = {'this'}
class Update(sqlglot.expressions.core.Expression, DML):
295class Update(Expression, DML):
296    arg_types = {
297        "with_": False,
298        "this": False,
299        "expressions": False,
300        "from_": False,
301        "where": False,
302        "returning": False,
303        "order": False,
304        "limit": False,
305        "options": False,
306        "hint": False,
307    }
308
309    def table(
310        self,
311        expression: ExpOrStr,
312        dialect: DialectType = None,
313        copy: bool = True,
314        **opts: Unpack[ParserNoDialectArgs],
315    ) -> Update:
316        """
317        Set the table to update.
318
319        Example:
320            >>> Update().table("my_table").set_("x = 1").sql()
321            'UPDATE my_table SET x = 1'
322
323        Args:
324            expression : the SQL code strings to parse.
325                If a `Table` instance is passed, this is used as-is.
326                If another `Expr` instance is passed, it will be wrapped in a `Table`.
327            dialect: the dialect used to parse the input expression.
328            copy: if `False`, modify this expression instance in-place.
329            opts: other options to use to parse the input expressions.
330
331        Returns:
332            The modified Update expression.
333        """
334        return _apply_builder(
335            expression=expression,
336            instance=self,
337            arg="this",
338            into=Table,
339            prefix=None,
340            dialect=dialect,
341            copy=copy,
342            **opts,
343        )
344
345    def set_(
346        self,
347        *expressions: ExpOrStr,
348        append: bool = True,
349        dialect: DialectType = None,
350        copy: bool = True,
351        **opts: Unpack[ParserNoDialectArgs],
352    ) -> Update:
353        """
354        Append to or set the SET expressions.
355
356        Example:
357            >>> Update().table("my_table").set_("x = 1").sql()
358            'UPDATE my_table SET x = 1'
359
360        Args:
361            *expressions: the SQL code strings to parse.
362                If `Expr` instance(s) are passed, they will be used as-is.
363                Multiple expressions are combined with a comma.
364            append: if `True`, add the new expressions to any existing SET expressions.
365                Otherwise, this resets the expressions.
366            dialect: the dialect used to parse the input expressions.
367            copy: if `False`, modify this expression instance in-place.
368            opts: other options to use to parse the input expressions.
369        """
370        return _apply_list_builder(
371            *expressions,
372            instance=self,
373            arg="expressions",
374            append=append,
375            into=Expr,
376            prefix=None,
377            dialect=dialect,
378            copy=copy,
379            **opts,
380        )
381
382    def where(
383        self,
384        *expressions: ExpOrStr | None,
385        append: bool = True,
386        dialect: DialectType = None,
387        copy: bool = True,
388        **opts: Unpack[ParserNoDialectArgs],
389    ) -> Update:
390        """
391        Append to or set the WHERE expressions.
392
393        Example:
394            >>> Update().table("tbl").set_("x = 1").where("x = 'a' OR x < 'b'").sql()
395            "UPDATE tbl SET x = 1 WHERE x = 'a' OR x < 'b'"
396
397        Args:
398            *expressions: the SQL code strings to parse.
399                If an `Expr` instance is passed, it will be used as-is.
400                Multiple expressions are combined with an AND operator.
401            append: if `True`, AND the new expressions to any existing expression.
402                Otherwise, this resets the expression.
403            dialect: the dialect used to parse the input expressions.
404            copy: if `False`, modify this expression instance in-place.
405            opts: other options to use to parse the input expressions.
406
407        Returns:
408            Update: the modified expression.
409        """
410        return _apply_conjunction_builder(
411            *expressions,
412            instance=self,
413            arg="where",
414            append=append,
415            into=Where,
416            dialect=dialect,
417            copy=copy,
418            **opts,
419        )
420
421    def from_(
422        self,
423        expression: ExpOrStr | None = None,
424        dialect: DialectType = None,
425        copy: bool = True,
426        **opts: Unpack[ParserNoDialectArgs],
427    ) -> Update:
428        """
429        Set the FROM expression.
430
431        Example:
432            >>> Update().table("my_table").set_("x = 1").from_("baz").sql()
433            'UPDATE my_table SET x = 1 FROM baz'
434
435        Args:
436            expression : the SQL code strings to parse.
437                If a `From` instance is passed, this is used as-is.
438                If another `Expr` instance is passed, it will be wrapped in a `From`.
439                If nothing is passed in then a from is not applied to the expression
440            dialect: the dialect used to parse the input expression.
441            copy: if `False`, modify this expression instance in-place.
442            opts: other options to use to parse the input expressions.
443
444        Returns:
445            The modified Update expression.
446        """
447        if not expression:
448            return maybe_copy(self, copy)
449
450        return _apply_builder(
451            expression=expression,
452            instance=self,
453            arg="from_",
454            into=From,
455            prefix="FROM",
456            dialect=dialect,
457            copy=copy,
458            **opts,
459        )
460
461    def with_(
462        self,
463        alias: ExpOrStr,
464        as_: ExpOrStr,
465        recursive: bool | None = None,
466        materialized: bool | None = None,
467        append: bool = True,
468        dialect: DialectType = None,
469        copy: bool = True,
470        **opts: Unpack[ParserNoDialectArgs],
471    ) -> Update:
472        """
473        Append to or set the common table expressions.
474
475        Example:
476            >>> Update().table("my_table").set_("x = 1").from_("baz").with_("baz", "SELECT id FROM foo").sql()
477            'WITH baz AS (SELECT id FROM foo) UPDATE my_table SET x = 1 FROM baz'
478
479        Args:
480            alias: the SQL code string to parse as the table name.
481                If an `Expr` instance is passed, this is used as-is.
482            as_: the SQL code string to parse as the table expression.
483                If an `Expr` instance is passed, it will be used as-is.
484            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
485            materialized: set the MATERIALIZED part of the expression.
486            append: if `True`, add to any existing expressions.
487                Otherwise, this resets the expressions.
488            dialect: the dialect used to parse the input expression.
489            copy: if `False`, modify this expression instance in-place.
490            opts: other options to use to parse the input expressions.
491
492        Returns:
493            The modified expression.
494        """
495        return _apply_cte_builder(
496            self,
497            alias,
498            as_,
499            recursive=recursive,
500            materialized=materialized,
501            append=append,
502            dialect=dialect,
503            copy=copy,
504            **opts,
505        )
arg_types = {'with_': False, 'this': False, 'expressions': False, 'from_': False, 'where': False, 'returning': False, 'order': False, 'limit': False, 'options': False, 'hint': False}
def table( self, expression: Union[int, str, sqlglot.expressions.core.Expr], dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, copy: bool = True, **opts: typing_extensions.Unpack[sqlglot._typing.ParserNoDialectArgs]) -> Update:
309    def table(
310        self,
311        expression: ExpOrStr,
312        dialect: DialectType = None,
313        copy: bool = True,
314        **opts: Unpack[ParserNoDialectArgs],
315    ) -> Update:
316        """
317        Set the table to update.
318
319        Example:
320            >>> Update().table("my_table").set_("x = 1").sql()
321            'UPDATE my_table SET x = 1'
322
323        Args:
324            expression : the SQL code strings to parse.
325                If a `Table` instance is passed, this is used as-is.
326                If another `Expr` instance is passed, it will be wrapped in a `Table`.
327            dialect: the dialect used to parse the input expression.
328            copy: if `False`, modify this expression instance in-place.
329            opts: other options to use to parse the input expressions.
330
331        Returns:
332            The modified Update expression.
333        """
334        return _apply_builder(
335            expression=expression,
336            instance=self,
337            arg="this",
338            into=Table,
339            prefix=None,
340            dialect=dialect,
341            copy=copy,
342            **opts,
343        )

Set the table to update.

Example:
>>> Update().table("my_table").set_("x = 1").sql()
'UPDATE my_table SET x = 1'
Arguments:
  • expression : the SQL code strings to parse. If a Table instance is passed, this is used as-is. If another Expr instance is passed, it will be wrapped in a Table.
  • dialect: the dialect used to parse the input expression.
  • copy: if False, modify this expression instance in-place.
  • opts: other options to use to parse the input expressions.
Returns:

The modified Update expression.

def set_( self, *expressions: Union[int, str, sqlglot.expressions.core.Expr], append: bool = True, dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, copy: bool = True, **opts: typing_extensions.Unpack[sqlglot._typing.ParserNoDialectArgs]) -> Update:
345    def set_(
346        self,
347        *expressions: ExpOrStr,
348        append: bool = True,
349        dialect: DialectType = None,
350        copy: bool = True,
351        **opts: Unpack[ParserNoDialectArgs],
352    ) -> Update:
353        """
354        Append to or set the SET expressions.
355
356        Example:
357            >>> Update().table("my_table").set_("x = 1").sql()
358            'UPDATE my_table SET x = 1'
359
360        Args:
361            *expressions: the SQL code strings to parse.
362                If `Expr` instance(s) are passed, they will be used as-is.
363                Multiple expressions are combined with a comma.
364            append: if `True`, add the new expressions to any existing SET expressions.
365                Otherwise, this resets the expressions.
366            dialect: the dialect used to parse the input expressions.
367            copy: if `False`, modify this expression instance in-place.
368            opts: other options to use to parse the input expressions.
369        """
370        return _apply_list_builder(
371            *expressions,
372            instance=self,
373            arg="expressions",
374            append=append,
375            into=Expr,
376            prefix=None,
377            dialect=dialect,
378            copy=copy,
379            **opts,
380        )

Append to or set the SET expressions.

Example:
>>> Update().table("my_table").set_("x = 1").sql()
'UPDATE my_table SET x = 1'
Arguments:
  • *expressions: the SQL code strings to parse. If Expr instance(s) are passed, they will be used as-is. Multiple expressions are combined with a comma.
  • append: if True, add the new expressions to any existing SET expressions. Otherwise, this resets the expressions.
  • dialect: the dialect used to parse the input expressions.
  • copy: if False, modify this expression instance in-place.
  • opts: other options to use to parse the input expressions.
def where( self, *expressions: Union[int, str, sqlglot.expressions.core.Expr, NoneType], append: bool = True, dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, copy: bool = True, **opts: typing_extensions.Unpack[sqlglot._typing.ParserNoDialectArgs]) -> Update:
382    def where(
383        self,
384        *expressions: ExpOrStr | None,
385        append: bool = True,
386        dialect: DialectType = None,
387        copy: bool = True,
388        **opts: Unpack[ParserNoDialectArgs],
389    ) -> Update:
390        """
391        Append to or set the WHERE expressions.
392
393        Example:
394            >>> Update().table("tbl").set_("x = 1").where("x = 'a' OR x < 'b'").sql()
395            "UPDATE tbl SET x = 1 WHERE x = 'a' OR x < 'b'"
396
397        Args:
398            *expressions: the SQL code strings to parse.
399                If an `Expr` instance is passed, it will be used as-is.
400                Multiple expressions are combined with an AND operator.
401            append: if `True`, AND the new expressions to any existing expression.
402                Otherwise, this resets the expression.
403            dialect: the dialect used to parse the input expressions.
404            copy: if `False`, modify this expression instance in-place.
405            opts: other options to use to parse the input expressions.
406
407        Returns:
408            Update: the modified expression.
409        """
410        return _apply_conjunction_builder(
411            *expressions,
412            instance=self,
413            arg="where",
414            append=append,
415            into=Where,
416            dialect=dialect,
417            copy=copy,
418            **opts,
419        )

Append to or set the WHERE expressions.

Example:
>>> Update().table("tbl").set_("x = 1").where("x = 'a' OR x < 'b'").sql()
"UPDATE tbl SET x = 1 WHERE x = 'a' OR x < 'b'"
Arguments:
  • *expressions: the SQL code strings to parse. If an Expr instance is passed, it will be used as-is. Multiple expressions are combined with an AND operator.
  • append: if True, AND the new expressions to any existing expression. Otherwise, this resets the expression.
  • dialect: the dialect used to parse the input expressions.
  • copy: if False, modify this expression instance in-place.
  • opts: other options to use to parse the input expressions.
Returns:

Update: the modified expression.

def from_( self, expression: Union[int, str, sqlglot.expressions.core.Expr, NoneType] = None, dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, copy: bool = True, **opts: typing_extensions.Unpack[sqlglot._typing.ParserNoDialectArgs]) -> Update:
421    def from_(
422        self,
423        expression: ExpOrStr | None = None,
424        dialect: DialectType = None,
425        copy: bool = True,
426        **opts: Unpack[ParserNoDialectArgs],
427    ) -> Update:
428        """
429        Set the FROM expression.
430
431        Example:
432            >>> Update().table("my_table").set_("x = 1").from_("baz").sql()
433            'UPDATE my_table SET x = 1 FROM baz'
434
435        Args:
436            expression : the SQL code strings to parse.
437                If a `From` instance is passed, this is used as-is.
438                If another `Expr` instance is passed, it will be wrapped in a `From`.
439                If nothing is passed in then a from is not applied to the expression
440            dialect: the dialect used to parse the input expression.
441            copy: if `False`, modify this expression instance in-place.
442            opts: other options to use to parse the input expressions.
443
444        Returns:
445            The modified Update expression.
446        """
447        if not expression:
448            return maybe_copy(self, copy)
449
450        return _apply_builder(
451            expression=expression,
452            instance=self,
453            arg="from_",
454            into=From,
455            prefix="FROM",
456            dialect=dialect,
457            copy=copy,
458            **opts,
459        )

Set the FROM expression.

Example:
>>> Update().table("my_table").set_("x = 1").from_("baz").sql()
'UPDATE my_table SET x = 1 FROM baz'
Arguments:
  • expression : the SQL code strings to parse. If a From instance is passed, this is used as-is. If another Expr instance is passed, it will be wrapped in a From. If nothing is passed in then a from is not applied to the expression
  • dialect: the dialect used to parse the input expression.
  • copy: if False, modify this expression instance in-place.
  • opts: other options to use to parse the input expressions.
Returns:

The modified Update expression.

def with_( self, alias: Union[int, str, sqlglot.expressions.core.Expr], as_: Union[int, str, sqlglot.expressions.core.Expr], recursive: bool | None = None, materialized: bool | None = None, append: bool = True, dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, copy: bool = True, **opts: typing_extensions.Unpack[sqlglot._typing.ParserNoDialectArgs]) -> Update:
461    def with_(
462        self,
463        alias: ExpOrStr,
464        as_: ExpOrStr,
465        recursive: bool | None = None,
466        materialized: bool | None = None,
467        append: bool = True,
468        dialect: DialectType = None,
469        copy: bool = True,
470        **opts: Unpack[ParserNoDialectArgs],
471    ) -> Update:
472        """
473        Append to or set the common table expressions.
474
475        Example:
476            >>> Update().table("my_table").set_("x = 1").from_("baz").with_("baz", "SELECT id FROM foo").sql()
477            'WITH baz AS (SELECT id FROM foo) UPDATE my_table SET x = 1 FROM baz'
478
479        Args:
480            alias: the SQL code string to parse as the table name.
481                If an `Expr` instance is passed, this is used as-is.
482            as_: the SQL code string to parse as the table expression.
483                If an `Expr` instance is passed, it will be used as-is.
484            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
485            materialized: set the MATERIALIZED part of the expression.
486            append: if `True`, add to any existing expressions.
487                Otherwise, this resets the expressions.
488            dialect: the dialect used to parse the input expression.
489            copy: if `False`, modify this expression instance in-place.
490            opts: other options to use to parse the input expressions.
491
492        Returns:
493            The modified expression.
494        """
495        return _apply_cte_builder(
496            self,
497            alias,
498            as_,
499            recursive=recursive,
500            materialized=materialized,
501            append=append,
502            dialect=dialect,
503            copy=copy,
504            **opts,
505        )

Append to or set the common table expressions.

Example:
>>> Update().table("my_table").set_("x = 1").from_("baz").with_("baz", "SELECT id FROM foo").sql()
'WITH baz AS (SELECT id FROM foo) UPDATE my_table SET x = 1 FROM baz'
Arguments:
  • alias: the SQL code string to parse as the table name. If an Expr instance is passed, this is used as-is.
  • as_: the SQL code string to parse as the table expression. If an Expr instance is passed, it will be used as-is.
  • recursive: set the RECURSIVE part of the expression. Defaults to False.
  • materialized: set the MATERIALIZED part of the expression.
  • append: if True, add to any existing expressions. Otherwise, this resets the expressions.
  • dialect: the dialect used to parse the input expression.
  • copy: if False, modify this expression instance in-place.
  • opts: other options to use to parse the input expressions.
Returns:

The modified expression.

key: ClassVar[str] = 'update'
required_args: 't.ClassVar[set[str]]' = set()
class Merge(sqlglot.expressions.core.Expression, DML):
508class Merge(Expression, DML):
509    arg_types = {
510        "this": True,
511        "using": True,
512        "on": False,
513        "using_cond": False,
514        "whens": True,
515        "with_": False,
516        "returning": False,
517    }
arg_types = {'this': True, 'using': True, 'on': False, 'using_cond': False, 'whens': True, 'with_': False, 'returning': False}
key: ClassVar[str] = 'merge'
required_args: 't.ClassVar[set[str]]' = {'whens', 'using', 'this'}
class When(sqlglot.expressions.core.Expression):
520class When(Expression):
521    arg_types = {"matched": True, "source": False, "condition": False, "then": True}
arg_types = {'matched': True, 'source': False, 'condition': False, 'then': True}
key: ClassVar[str] = 'when'
required_args: 't.ClassVar[set[str]]' = {'matched', 'then'}
class Whens(sqlglot.expressions.core.Expression):
524class Whens(Expression):
525    """Wraps around one or more WHEN [NOT] MATCHED [...] clauses."""
526
527    arg_types = {"expressions": True}

Wraps around one or more WHEN [NOT] MATCHED [...] clauses.

arg_types = {'expressions': True}
key: ClassVar[str] = 'whens'
required_args: 't.ClassVar[set[str]]' = {'expressions'}