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        "using": 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        )
264
265
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    }
276
277
278class Returning(Expression):
279    arg_types = {"expressions": True, "into": False}
280
281
282class LoadData(Expression):
283    arg_types = {
284        "this": True,
285        "local": False,
286        "overwrite": False,
287        "temp": False,
288        "inpath": False,
289        "files": False,
290        "partition": False,
291        "input_format": False,
292        "serde": False,
293    }
294
295
296class Update(Expression, DML):
297    arg_types = {
298        "with_": False,
299        "this": False,
300        "expressions": False,
301        "from_": False,
302        "where": False,
303        "returning": False,
304        "order": False,
305        "limit": False,
306        "options": False,
307        "hint": False,
308    }
309
310    def table(
311        self,
312        expression: ExpOrStr,
313        dialect: DialectType = None,
314        copy: bool = True,
315        **opts: Unpack[ParserNoDialectArgs],
316    ) -> Update:
317        """
318        Set the table to update.
319
320        Example:
321            >>> Update().table("my_table").set_("x = 1").sql()
322            'UPDATE my_table SET x = 1'
323
324        Args:
325            expression : the SQL code strings to parse.
326                If a `Table` instance is passed, this is used as-is.
327                If another `Expr` instance is passed, it will be wrapped in a `Table`.
328            dialect: the dialect used to parse the input expression.
329            copy: if `False`, modify this expression instance in-place.
330            opts: other options to use to parse the input expressions.
331
332        Returns:
333            The modified Update expression.
334        """
335        return _apply_builder(
336            expression=expression,
337            instance=self,
338            arg="this",
339            into=Table,
340            prefix=None,
341            dialect=dialect,
342            copy=copy,
343            **opts,
344        )
345
346    def set_(
347        self,
348        *expressions: ExpOrStr,
349        append: bool = True,
350        dialect: DialectType = None,
351        copy: bool = True,
352        **opts: Unpack[ParserNoDialectArgs],
353    ) -> Update:
354        """
355        Append to or set the SET expressions.
356
357        Example:
358            >>> Update().table("my_table").set_("x = 1").sql()
359            'UPDATE my_table SET x = 1'
360
361        Args:
362            *expressions: the SQL code strings to parse.
363                If `Expr` instance(s) are passed, they will be used as-is.
364                Multiple expressions are combined with a comma.
365            append: if `True`, add the new expressions to any existing SET expressions.
366                Otherwise, this resets the expressions.
367            dialect: the dialect used to parse the input expressions.
368            copy: if `False`, modify this expression instance in-place.
369            opts: other options to use to parse the input expressions.
370        """
371        return _apply_list_builder(
372            *expressions,
373            instance=self,
374            arg="expressions",
375            append=append,
376            into=Expr,
377            prefix=None,
378            dialect=dialect,
379            copy=copy,
380            **opts,
381        )
382
383    def where(
384        self,
385        *expressions: ExpOrStr | None,
386        append: bool = True,
387        dialect: DialectType = None,
388        copy: bool = True,
389        **opts: Unpack[ParserNoDialectArgs],
390    ) -> Update:
391        """
392        Append to or set the WHERE expressions.
393
394        Example:
395            >>> Update().table("tbl").set_("x = 1").where("x = 'a' OR x < 'b'").sql()
396            "UPDATE tbl SET x = 1 WHERE x = 'a' OR x < 'b'"
397
398        Args:
399            *expressions: the SQL code strings to parse.
400                If an `Expr` instance is passed, it will be used as-is.
401                Multiple expressions are combined with an AND operator.
402            append: if `True`, AND the new expressions to any existing expression.
403                Otherwise, this resets the expression.
404            dialect: the dialect used to parse the input expressions.
405            copy: if `False`, modify this expression instance in-place.
406            opts: other options to use to parse the input expressions.
407
408        Returns:
409            Update: the modified expression.
410        """
411        return _apply_conjunction_builder(
412            *expressions,
413            instance=self,
414            arg="where",
415            append=append,
416            into=Where,
417            dialect=dialect,
418            copy=copy,
419            **opts,
420        )
421
422    def from_(
423        self,
424        expression: ExpOrStr | None = None,
425        dialect: DialectType = None,
426        copy: bool = True,
427        **opts: Unpack[ParserNoDialectArgs],
428    ) -> Update:
429        """
430        Set the FROM expression.
431
432        Example:
433            >>> Update().table("my_table").set_("x = 1").from_("baz").sql()
434            'UPDATE my_table SET x = 1 FROM baz'
435
436        Args:
437            expression : the SQL code strings to parse.
438                If a `From` instance is passed, this is used as-is.
439                If another `Expr` instance is passed, it will be wrapped in a `From`.
440                If nothing is passed in then a from is not applied to the expression
441            dialect: the dialect used to parse the input expression.
442            copy: if `False`, modify this expression instance in-place.
443            opts: other options to use to parse the input expressions.
444
445        Returns:
446            The modified Update expression.
447        """
448        if not expression:
449            return maybe_copy(self, copy)
450
451        return _apply_builder(
452            expression=expression,
453            instance=self,
454            arg="from_",
455            into=From,
456            prefix="FROM",
457            dialect=dialect,
458            copy=copy,
459            **opts,
460        )
461
462    def with_(
463        self,
464        alias: ExpOrStr,
465        as_: ExpOrStr,
466        recursive: bool | None = None,
467        materialized: bool | None = None,
468        append: bool = True,
469        dialect: DialectType = None,
470        copy: bool = True,
471        **opts: Unpack[ParserNoDialectArgs],
472    ) -> Update:
473        """
474        Append to or set the common table expressions.
475
476        Example:
477            >>> Update().table("my_table").set_("x = 1").from_("baz").with_("baz", "SELECT id FROM foo").sql()
478            'WITH baz AS (SELECT id FROM foo) UPDATE my_table SET x = 1 FROM baz'
479
480        Args:
481            alias: the SQL code string to parse as the table name.
482                If an `Expr` instance is passed, this is used as-is.
483            as_: the SQL code string to parse as the table expression.
484                If an `Expr` instance is passed, it will be used as-is.
485            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
486            materialized: set the MATERIALIZED part of the expression.
487            append: if `True`, add to any existing expressions.
488                Otherwise, this resets the expressions.
489            dialect: the dialect used to parse the input expression.
490            copy: if `False`, modify this expression instance in-place.
491            opts: other options to use to parse the input expressions.
492
493        Returns:
494            The modified expression.
495        """
496        return _apply_cte_builder(
497            self,
498            alias,
499            as_,
500            recursive=recursive,
501            materialized=materialized,
502            append=append,
503            dialect=dialect,
504            copy=copy,
505            **opts,
506        )
507
508
509class Merge(Expression, DML):
510    arg_types = {
511        "this": True,
512        "using": True,
513        "on": False,
514        "using_cond": False,
515        "whens": True,
516        "with_": False,
517        "returning": False,
518    }
519
520
521class When(Expression):
522    arg_types = {"matched": True, "source": False, "condition": False, "then": True}
523
524
525class Whens(Expression):
526    """Wraps around one or more WHEN [NOT] MATCHED [...] clauses."""
527
528    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        "using": False,
217    }
218
219    def with_(
220        self,
221        alias: ExpOrStr,
222        as_: ExpOrStr,
223        recursive: bool | None = None,
224        materialized: bool | None = None,
225        append: bool = True,
226        dialect: DialectType = None,
227        copy: bool = True,
228        **opts: Unpack[ParserNoDialectArgs],
229    ) -> Insert:
230        """
231        Append to or set the common table expressions.
232
233        Example:
234            >>> import sqlglot
235            >>> sqlglot.parse_one("INSERT INTO t SELECT x FROM cte").with_("cte", as_="SELECT * FROM tbl").sql()
236            'WITH cte AS (SELECT * FROM tbl) INSERT INTO t SELECT x FROM cte'
237
238        Args:
239            alias: the SQL code string to parse as the table name.
240                If an `Expr` instance is passed, this is used as-is.
241            as_: the SQL code string to parse as the table expression.
242                If an `Expr` instance is passed, it will be used as-is.
243            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
244            materialized: set the MATERIALIZED part of the expression.
245            append: if `True`, add to any existing expressions.
246                Otherwise, this resets the expressions.
247            dialect: the dialect used to parse the input expression.
248            copy: if `False`, modify this expression instance in-place.
249            opts: other options to use to parse the input expressions.
250
251        Returns:
252            The modified expression.
253        """
254        return _apply_cte_builder(
255            self,
256            alias,
257            as_,
258            recursive=recursive,
259            materialized=materialized,
260            append=append,
261            dialect=dialect,
262            copy=copy,
263            **opts,
264        )
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, 'using': 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:
219    def with_(
220        self,
221        alias: ExpOrStr,
222        as_: ExpOrStr,
223        recursive: bool | None = None,
224        materialized: bool | None = None,
225        append: bool = True,
226        dialect: DialectType = None,
227        copy: bool = True,
228        **opts: Unpack[ParserNoDialectArgs],
229    ) -> Insert:
230        """
231        Append to or set the common table expressions.
232
233        Example:
234            >>> import sqlglot
235            >>> sqlglot.parse_one("INSERT INTO t SELECT x FROM cte").with_("cte", as_="SELECT * FROM tbl").sql()
236            'WITH cte AS (SELECT * FROM tbl) INSERT INTO t SELECT x FROM cte'
237
238        Args:
239            alias: the SQL code string to parse as the table name.
240                If an `Expr` instance is passed, this is used as-is.
241            as_: the SQL code string to parse as the table expression.
242                If an `Expr` instance is passed, it will be used as-is.
243            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
244            materialized: set the MATERIALIZED part of the expression.
245            append: if `True`, add to any existing expressions.
246                Otherwise, this resets the expressions.
247            dialect: the dialect used to parse the input expression.
248            copy: if `False`, modify this expression instance in-place.
249            opts: other options to use to parse the input expressions.
250
251        Returns:
252            The modified expression.
253        """
254        return _apply_cte_builder(
255            self,
256            alias,
257            as_,
258            recursive=recursive,
259            materialized=materialized,
260            append=append,
261            dialect=dialect,
262            copy=copy,
263            **opts,
264        )

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

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

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

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

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

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):
510class Merge(Expression, DML):
511    arg_types = {
512        "this": True,
513        "using": True,
514        "on": False,
515        "using_cond": False,
516        "whens": True,
517        "with_": False,
518        "returning": False,
519    }
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]]' = {'using', 'whens', 'this'}
class When(sqlglot.expressions.core.Expression):
522class When(Expression):
523    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]]' = {'then', 'matched'}
class Whens(sqlglot.expressions.core.Expression):
526class Whens(Expression):
527    """Wraps around one or more WHEN [NOT] MATCHED [...] clauses."""
528
529    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'}