@@ -1978,7 +1978,7 @@ def _get_alter_sql(self, **params) -> str:
1978
1978
value = params .get ('value' )
1979
1979
inc = params .get ('increment' )
1980
1980
cmd = f'ALTER { self .schema .opt_generator_keyword } { self .get_quoted_name ()} ' \
1981
- f'{ f"START WITH { value } " if isinstance (value ,int ) else "" } ' \
1981
+ f'{ f"RESTART WITH { value } " if isinstance (value ,int ) else "" } ' \
1982
1982
f'{ f"INCREMENT BY { inc } " if inc else "" } '
1983
1983
return cmd .strip ()
1984
1984
def _get_drop_sql (self , ** params ) -> str :
@@ -2830,7 +2830,7 @@ def _get_create_sql(self, **params) -> str:
2830
2830
i = self .index
2831
2831
const_def += f" ({ ',' .join (i .segment_names )} )"
2832
2832
if not i .is_sys_object ():
2833
- const_def += f'\n USING { i .index_type } INDEX { i .get_quoted_name ()} '
2833
+ const_def += f'\n USING { i .index_type . value } INDEX { i .get_quoted_name ()} '
2834
2834
elif self .is_fkey ():
2835
2835
const_def += f"FOREIGN KEY ({ ',' .join (self .index .segment_names )} )\n "
2836
2836
p = self .partner_constraint
@@ -2841,7 +2841,7 @@ def _get_create_sql(self, **params) -> str:
2841
2841
const_def += f'\n ON UPDATE { self .update_rule } '
2842
2842
i = self .index
2843
2843
if not i .is_sys_object ():
2844
- const_def += f'\n USING { i .index_type } INDEX { i .get_quoted_name ()} '
2844
+ const_def += f'\n USING { i .index_type . value } INDEX { i .get_quoted_name ()} '
2845
2845
else :
2846
2846
raise Error (f"Unrecognized constraint type '{ self .constraint_type } '" )
2847
2847
return const_def
@@ -2946,7 +2946,7 @@ class Table(SchemaItem):
2946
2946
2947
2947
Supported SQL actions:
2948
2948
- User table: `create` (no_pk=bool, no_unique=bool), `recreate` (no_pk=bool, no_unique=bool),
2949
- `drop`, `comment`
2949
+ `drop`, `comment`, `insert (update=bool, returning=list[str], matching=list[str])`
2950
2950
- System table: `comment`
2951
2951
"""
2952
2952
def __init__ (self , schema : Schema , attributes : Dict [str , Any ]):
@@ -2960,6 +2960,23 @@ def __init__(self, schema: Schema, attributes: Dict[str, Any]):
2960
2960
self ._actions .append ('comment' )
2961
2961
if not self .is_sys_object ():
2962
2962
self ._actions .extend (['create' , 'recreate' , 'drop' ])
2963
+ def _get_insert_sql (self , ** params ) -> str :
2964
+ try :
2965
+ self ._check_params (params , ['update' , 'returning' , 'matching' ])
2966
+ update = params .get ('update' , False )
2967
+ returning = params .get ('returning' )
2968
+ matching = params .get ('returning' )
2969
+ #
2970
+ result = f"{ 'UPDATE OR ' if update else '' } INSERT TABLE { self .get_quoted_name ()} "
2971
+ result += f" ({ ',' .join (col .get_quoted_name () for col in self .columns )} )"
2972
+ result += f" VALUES ({ ',' .join ('?' for col in self .columns )} )"
2973
+ if matching :
2974
+ result += f" MATCHING ({ ',' .join (matching )} )"
2975
+ if returning :
2976
+ result += f" RETURNING ({ ',' .join (returning )} )"
2977
+ return result
2978
+ except Exception as e :
2979
+ raise e
2963
2980
def _get_create_sql (self , ** params ) -> str :
2964
2981
try :
2965
2982
self ._check_params (params , ['no_pk' , 'no_unique' ])
@@ -3009,7 +3026,7 @@ def _get_create_sql(self, **params) -> str:
3009
3026
i = pk .index
3010
3027
pkdef += f"PRIMARY KEY ({ ',' .join (i .segment_names )} )"
3011
3028
if not i .is_sys_object ():
3012
- pkdef += f'\n USING { i .index_type } INDEX { i .get_quoted_name ()} '
3029
+ pkdef += f'\n USING { i .index_type . value } INDEX { i .get_quoted_name ()} '
3013
3030
partdefs .append (pkdef )
3014
3031
if not no_unique :
3015
3032
for uq in self .constraints :
@@ -3020,7 +3037,7 @@ def _get_create_sql(self, **params) -> str:
3020
3037
i = uq .index
3021
3038
uqdef += f"UNIQUE ({ ',' .join (i .segment_names )} )"
3022
3039
if not i .is_sys_object ():
3023
- uqdef += f'\n USING { i .index_type } INDEX { i .get_quoted_name ()} '
3040
+ uqdef += f'\n USING { i .index_type . value } INDEX { i .get_quoted_name ()} '
3024
3041
partdefs .append (uqdef )
3025
3042
tabdef += ',' .join (partdefs )
3026
3043
tabdef += '\n )'
0 commit comments