@@ -70,6 +70,7 @@ static void PublicationDropTables(Oid pubid, List *rels, bool missing_ok);
70
70
static void PublicationAddSchemas (Oid pubid , List * schemas , bool if_not_exists ,
71
71
AlterPublicationStmt * stmt );
72
72
static void PublicationDropSchemas (Oid pubid , List * schemas , bool missing_ok );
73
+ static char defGetGeneratedColsOption (DefElem * def );
73
74
74
75
75
76
static void
@@ -80,7 +81,7 @@ parse_publication_options(ParseState *pstate,
80
81
bool * publish_via_partition_root_given ,
81
82
bool * publish_via_partition_root ,
82
83
bool * publish_generated_columns_given ,
83
- bool * publish_generated_columns )
84
+ char * publish_generated_columns )
84
85
{
85
86
ListCell * lc ;
86
87
@@ -94,7 +95,7 @@ parse_publication_options(ParseState *pstate,
94
95
pubactions -> pubdelete = true;
95
96
pubactions -> pubtruncate = true;
96
97
* publish_via_partition_root = false;
97
- * publish_generated_columns = false ;
98
+ * publish_generated_columns = PUBLISH_GENCOLS_NONE ;
98
99
99
100
/* Parse options */
100
101
foreach (lc , options )
@@ -160,7 +161,7 @@ parse_publication_options(ParseState *pstate,
160
161
if (* publish_generated_columns_given )
161
162
errorConflictingDefElem (defel , pstate );
162
163
* publish_generated_columns_given = true;
163
- * publish_generated_columns = defGetBoolean (defel );
164
+ * publish_generated_columns = defGetGeneratedColsOption (defel );
164
165
}
165
166
else
166
167
ereport (ERROR ,
@@ -344,15 +345,16 @@ pub_rf_contains_invalid_column(Oid pubid, Relation relation, List *ancestors,
344
345
* by the column list. If any column is missing, *invalid_column_list is set
345
346
* to true.
346
347
* 2. Ensures that all the generated columns referenced in the REPLICA IDENTITY
347
- * are published either by listing them in the column list or by enabling
348
- * publish_generated_columns option. If any unpublished generated column is
349
- * found, *invalid_gen_col is set to true.
348
+ * are published, either by being explicitly named in the column list or, if
349
+ * no column list is specified, by setting the option
350
+ * publish_generated_columns to stored. If any unpublished
351
+ * generated column is found, *invalid_gen_col is set to true.
350
352
*
351
353
* Returns true if any of the above conditions are not met.
352
354
*/
353
355
bool
354
356
pub_contains_invalid_column (Oid pubid , Relation relation , List * ancestors ,
355
- bool pubviaroot , bool pubgencols ,
357
+ bool pubviaroot , char pubgencols_type ,
356
358
bool * invalid_column_list ,
357
359
bool * invalid_gen_col )
358
360
{
@@ -394,10 +396,10 @@ pub_contains_invalid_column(Oid pubid, Relation relation, List *ancestors,
394
396
395
397
/*
396
398
* As we don't allow a column list with REPLICA IDENTITY FULL, the
397
- * publish_generated_columns option must be set to true if the table
399
+ * publish_generated_columns option must be set to stored if the table
398
400
* has any stored generated columns.
399
401
*/
400
- if (! pubgencols &&
402
+ if (pubgencols_type != PUBLISH_GENCOLS_STORED &&
401
403
relation -> rd_att -> constr &&
402
404
relation -> rd_att -> constr -> has_generated_stored )
403
405
* invalid_gen_col = true;
@@ -425,10 +427,10 @@ pub_contains_invalid_column(Oid pubid, Relation relation, List *ancestors,
425
427
if (columns == NULL )
426
428
{
427
429
/*
428
- * The publish_generated_columns option must be set to true if the
429
- * REPLICA IDENTITY contains any stored generated column.
430
+ * The publish_generated_columns option must be set to stored if
431
+ * the REPLICA IDENTITY contains any stored generated column.
430
432
*/
431
- if (! pubgencols && att -> attgenerated )
433
+ if (pubgencols_type != PUBLISH_GENCOLS_STORED && att -> attgenerated )
432
434
{
433
435
* invalid_gen_col = true;
434
436
break ;
@@ -775,7 +777,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
775
777
bool publish_via_partition_root_given ;
776
778
bool publish_via_partition_root ;
777
779
bool publish_generated_columns_given ;
778
- bool publish_generated_columns ;
780
+ char publish_generated_columns ;
779
781
AclResult aclresult ;
780
782
List * relations = NIL ;
781
783
List * schemaidlist = NIL ;
@@ -834,8 +836,8 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
834
836
BoolGetDatum (pubactions .pubtruncate );
835
837
values [Anum_pg_publication_pubviaroot - 1 ] =
836
838
BoolGetDatum (publish_via_partition_root );
837
- values [Anum_pg_publication_pubgencols - 1 ] =
838
- BoolGetDatum (publish_generated_columns );
839
+ values [Anum_pg_publication_pubgencols_type - 1 ] =
840
+ CharGetDatum (publish_generated_columns );
839
841
840
842
tup = heap_form_tuple (RelationGetDescr (rel ), values , nulls );
841
843
@@ -922,7 +924,7 @@ AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt,
922
924
bool publish_via_partition_root_given ;
923
925
bool publish_via_partition_root ;
924
926
bool publish_generated_columns_given ;
925
- bool publish_generated_columns ;
927
+ char publish_generated_columns ;
926
928
ObjectAddress obj ;
927
929
Form_pg_publication pubform ;
928
930
List * root_relids = NIL ;
@@ -1046,8 +1048,8 @@ AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt,
1046
1048
1047
1049
if (publish_generated_columns_given )
1048
1050
{
1049
- values [Anum_pg_publication_pubgencols - 1 ] = BoolGetDatum (publish_generated_columns );
1050
- replaces [Anum_pg_publication_pubgencols - 1 ] = true;
1051
+ values [Anum_pg_publication_pubgencols_type - 1 ] = CharGetDatum (publish_generated_columns );
1052
+ replaces [Anum_pg_publication_pubgencols_type - 1 ] = true;
1051
1053
}
1052
1054
1053
1055
tup = heap_modify_tuple (tup , RelationGetDescr (rel ), values , nulls ,
@@ -2043,3 +2045,33 @@ AlterPublicationOwner_oid(Oid subid, Oid newOwnerId)
2043
2045
2044
2046
table_close (rel , RowExclusiveLock );
2045
2047
}
2048
+
2049
+ /*
2050
+ * Extract the publish_generated_columns option value from a DefElem. "stored"
2051
+ * and "none" values are accepted.
2052
+ */
2053
+ static char
2054
+ defGetGeneratedColsOption (DefElem * def )
2055
+ {
2056
+ char * sval ;
2057
+
2058
+ /*
2059
+ * If no parameter value given, assume "stored" is meant.
2060
+ */
2061
+ if (!def -> arg )
2062
+ return PUBLISH_GENCOLS_STORED ;
2063
+
2064
+ sval = defGetString (def );
2065
+
2066
+ if (pg_strcasecmp (sval , "none" ) == 0 )
2067
+ return PUBLISH_GENCOLS_NONE ;
2068
+ if (pg_strcasecmp (sval , "stored" ) == 0 )
2069
+ return PUBLISH_GENCOLS_STORED ;
2070
+
2071
+ ereport (ERROR ,
2072
+ errcode (ERRCODE_SYNTAX_ERROR ),
2073
+ errmsg ("%s requires a \"none\" or \"stored\" value" ,
2074
+ def -> defname ));
2075
+
2076
+ return PUBLISH_GENCOLS_NONE ; /* keep compiler quiet */
2077
+ }
0 commit comments