@@ -1978,7 +1978,7 @@ def _get_alter_sql(self, **params) -> str:
19781978 value = params .get ('value' )
19791979 inc = params .get ('increment' )
19801980 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 "" } ' \
19821982 f'{ f"INCREMENT BY { inc } " if inc else "" } '
19831983 return cmd .strip ()
19841984 def _get_drop_sql (self , ** params ) -> str :
@@ -2830,7 +2830,7 @@ def _get_create_sql(self, **params) -> str:
28302830 i = self .index
28312831 const_def += f" ({ ',' .join (i .segment_names )} )"
28322832 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 ()} '
28342834 elif self .is_fkey ():
28352835 const_def += f"FOREIGN KEY ({ ',' .join (self .index .segment_names )} )\n "
28362836 p = self .partner_constraint
@@ -2841,7 +2841,7 @@ def _get_create_sql(self, **params) -> str:
28412841 const_def += f'\n ON UPDATE { self .update_rule } '
28422842 i = self .index
28432843 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 ()} '
28452845 else :
28462846 raise Error (f"Unrecognized constraint type '{ self .constraint_type } '" )
28472847 return const_def
@@ -2946,7 +2946,7 @@ class Table(SchemaItem):
29462946
29472947 Supported SQL actions:
29482948 - 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])`
29502950 - System table: `comment`
29512951 """
29522952 def __init__ (self , schema : Schema , attributes : Dict [str , Any ]):
@@ -2960,6 +2960,23 @@ def __init__(self, schema: Schema, attributes: Dict[str, Any]):
29602960 self ._actions .append ('comment' )
29612961 if not self .is_sys_object ():
29622962 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
29632980 def _get_create_sql (self , ** params ) -> str :
29642981 try :
29652982 self ._check_params (params , ['no_pk' , 'no_unique' ])
@@ -3009,7 +3026,7 @@ def _get_create_sql(self, **params) -> str:
30093026 i = pk .index
30103027 pkdef += f"PRIMARY KEY ({ ',' .join (i .segment_names )} )"
30113028 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 ()} '
30133030 partdefs .append (pkdef )
30143031 if not no_unique :
30153032 for uq in self .constraints :
@@ -3020,7 +3037,7 @@ def _get_create_sql(self, **params) -> str:
30203037 i = uq .index
30213038 uqdef += f"UNIQUE ({ ',' .join (i .segment_names )} )"
30223039 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 ()} '
30243041 partdefs .append (uqdef )
30253042 tabdef += ',' .join (partdefs )
30263043 tabdef += '\n )'
0 commit comments