@@ -6043,6 +6043,7 @@ BEGIN
6043
6043
IF ((context- > ' bool' )::bool IS TRUE) THEN
6044
6044
fmt_str = ' (%s)' ;
6045
6045
END IF;
6046
+
6046
6047
ctx = jsonb_set(context, ' {bool}' , to_jsonb(TRUE));
6047
6048
6048
6049
IF (boolop = ' AND_EXPR' ) THEN
@@ -6327,6 +6328,7 @@ CREATE FUNCTION deparser.boolean_test ( node jsonb, context jsonb DEFAULT '{}'::
6327
6328
DECLARE
6328
6329
output text [];
6329
6330
booltesttype text ;
6331
+ ctx jsonb;
6330
6332
BEGIN
6331
6333
6332
6334
IF (node- > ' BooleanTest' ) IS NULL THEN
@@ -6345,7 +6347,9 @@ BEGIN
6345
6347
6346
6348
booltesttype = node- >> ' booltesttype' ;
6347
6349
6348
- output = array_append(output, deparser .expression (node- > ' arg' ));
6350
+ ctx = jsonb_set(context, ' {bool}' , to_jsonb(TRUE));
6351
+
6352
+ output = array_append(output, deparser .expression (node- > ' arg' , ctx));
6349
6353
6350
6354
output = array_append(output, (CASE
6351
6355
WHEN booltesttype = ' IS_TRUE' THEN ' IS TRUE'
@@ -6957,6 +6961,31 @@ BEGIN
6957
6961
END;
6958
6962
$EOFCODE$ LANGUAGE plpgsql IMMUTABLE;
6959
6963
6964
+ CREATE FUNCTION deparser .alter_seq_stmt ( node jsonb, context jsonb DEFAULT ' {}' ::jsonb ) RETURNS text AS $EOFCODE$
6965
+ DECLARE
6966
+ output text [];
6967
+ BEGIN
6968
+ IF (node- > ' AlterSeqStmt' ) IS NULL THEN
6969
+ RAISE EXCEPTION ' BAD_EXPRESSION %' , ' AlterSeqStmt' ;
6970
+ END IF;
6971
+
6972
+ IF (node- > ' AlterSeqStmt' - > ' sequence' ) IS NULL THEN
6973
+ RAISE EXCEPTION ' BAD_EXPRESSION %' , ' AlterSeqStmt' ;
6974
+ END IF;
6975
+
6976
+ node = node- > ' AlterSeqStmt' ;
6977
+
6978
+ output = array_append(output, ' ALTER SEQUENCE' );
6979
+ output = array_append(output, deparser .range_var (node- > ' sequence' ));
6980
+
6981
+ IF (node- > ' options' IS NOT NULL AND jsonb_array_length(node- > ' options' ) > 0 ) THEN
6982
+ output = array_append(output, deparser .list (node- > ' options' , ' ' , jsonb_set(context, ' {sequence}' , to_jsonb(TRUE))));
6983
+ END IF;
6984
+
6985
+ RETURN array_to_string(output, ' ' );
6986
+ END;
6987
+ $EOFCODE$ LANGUAGE plpgsql IMMUTABLE;
6988
+
6960
6989
CREATE FUNCTION deparser .do_stmt ( node jsonb, context jsonb DEFAULT ' {}' ::jsonb ) RETURNS text AS $EOFCODE$
6961
6990
DECLARE
6962
6991
output text [];
@@ -7095,6 +7124,7 @@ $EOFCODE$ LANGUAGE plpgsql IMMUTABLE;
7095
7124
CREATE FUNCTION deparser .def_elem ( node jsonb, context jsonb DEFAULT ' {}' ::jsonb ) RETURNS text AS $EOFCODE$
7096
7125
DECLARE
7097
7126
defname text ;
7127
+ output text [];
7098
7128
BEGIN
7099
7129
IF (node- > ' DefElem' ) IS NULL THEN
7100
7130
RAISE EXCEPTION ' BAD_EXPRESSION %' , ' DefElem' ;
@@ -7162,6 +7192,33 @@ BEGIN
7162
7192
ELSE
7163
7193
RETURN defname || ' ' || deparser .expression (node- > ' arg' , jsonb_set(context, ' {simple}' , to_jsonb(TRUE)));
7164
7194
END IF;
7195
+ ELSIF (defname = ' owned_by' ) THEN
7196
+ output = ARRAY[' OWNED BY' ]::text ;
7197
+
7198
+ IF (node- > ' arg' IS NOT NULL AND jsonb_array_length(node- > ' arg' ) > 0 ) THEN
7199
+ output = array_append(output, deparser .list_quotes (node- > ' arg' , ' .' , jsonb_set(context, ' {sequence}' , to_jsonb(TRUE))));
7200
+ END IF;
7201
+
7202
+ RETURN array_to_string(output, ' ' );
7203
+
7204
+ ELSIF (defname = ' start' ) THEN
7205
+
7206
+ output = ARRAY[' START WITH' ]::text ;
7207
+ output = array_append(output, deparser .expression (node- > ' arg' , jsonb_set(context, ' {sequence}' , to_jsonb(TRUE))));
7208
+
7209
+ RETURN array_to_string(output, ' ' );
7210
+
7211
+ ELSIF (defname = ' restart' ) THEN
7212
+
7213
+ IF (node- > ' arg' IS NOT NULL ) THEN
7214
+ output = ARRAY[' RESTART WITH' ]::text ;
7215
+ output = array_append(output, deparser .expression (node- > ' arg' , jsonb_set(context, ' {sequence}' , to_jsonb(TRUE))));
7216
+ ELSE
7217
+ output = ARRAY[' RESTART' ]::text ;
7218
+ END IF;
7219
+
7220
+ RETURN array_to_string(output, ' ' );
7221
+
7165
7222
ELSIF (node- > ' arg' IS NOT NULL ) THEN
7166
7223
RETURN defname || ' ' || deparser .expression (node- > ' arg' , jsonb_set(context, ' {simple}' , to_jsonb(TRUE)));
7167
7224
END IF;
@@ -9166,6 +9223,18 @@ BEGIN
9166
9223
output = array_append(output, ' TO' );
9167
9224
output = array_append(output, quote_ident(node- >> ' newname' ));
9168
9225
9226
+ ELSEIF ( renameType = ' OBJECT_SCHEMA' ) THEN
9227
+
9228
+ output = array_append(output, ' ALTER' );
9229
+ output = array_append(output, ' SCHEMA' );
9230
+ IF ((node- > ' missing_ok' )::bool is TRUE) THEN
9231
+ output = array_append(output, ' IF EXISTS' );
9232
+ END IF;
9233
+ output = array_append(output, quote_ident(node- >> ' subname' ));
9234
+ output = array_append(output, ' RENAME' );
9235
+ output = array_append(output, ' TO' );
9236
+ output = array_append(output, quote_ident(node- >> ' newname' ));
9237
+
9169
9238
ELSEIF ( renameType = ' OBJECT_DOMCONSTRAINT' ) THEN
9170
9239
9171
9240
output = array_append(output, ' ALTER' );
@@ -9944,6 +10013,8 @@ BEGIN
9944
10013
RETURN deparser .alter_enum_stmt (expr, context);
9945
10014
ELSEIF (expr- >> ' AlterPolicyStmt' ) IS NOT NULL THEN
9946
10015
RETURN deparser .alter_policy_stmt (expr, context);
10016
+ ELSEIF (expr- >> ' AlterSeqStmt' ) IS NOT NULL THEN
10017
+ RETURN deparser .alter_seq_stmt (expr, context);
9947
10018
ELSEIF (expr- >> ' AlterTableCmd' ) IS NOT NULL THEN
9948
10019
RETURN deparser .alter_table_cmd (expr, context);
9949
10020
ELSEIF (expr- >> ' AlterTableStmt' ) IS NOT NULL THEN
@@ -10175,11 +10246,14 @@ BEGIN
10175
10246
10176
10247
body = trim (format('
10177
10248
BEGIN
10178
- %1s
10179
- INTO %2s;
10249
+ IF (NEW.%1s IS NOT NULL) THEN
10250
+ %2s
10251
+ INTO %3s;
10252
+ END IF;
10180
10253
RETURN NEW;
10181
10254
END;
10182
10255
' ,
10256
+ v_table_field,
10183
10257
deparser .deparse (ast_expr),
10184
10258
deparser .list (to_jsonb(set_fields), E' ,\n ' )
10185
10259
));
0 commit comments