diff --git a/proto/pg_logicaldec.proto b/proto/pg_logicaldec.proto index 5a4504c..aad1363 100644 --- a/proto/pg_logicaldec.proto +++ b/proto/pg_logicaldec.proto @@ -32,6 +32,7 @@ message DatumMessage { message TypeInfo { required string modifier = 1; + required bool value_optional = 2; } message RowMessage { diff --git a/src/decoderbufs.c b/src/decoderbufs.c index 9c29864..ea8859f 100644 --- a/src/decoderbufs.c +++ b/src/decoderbufs.c @@ -640,6 +640,7 @@ static void add_metadata_to_msg(Decoderbufs__TypeInfo **tmsg, Form_pg_attribute attr; char *typ_mod; Decoderbufs__TypeInfo typeinfo = DECODERBUFS__TYPE_INFO__INIT; + bool not_null; attr = tupdesc->attrs[natt]; @@ -649,10 +650,12 @@ static void add_metadata_to_msg(Decoderbufs__TypeInfo **tmsg, continue; } + not_null = attr->attnotnull; typ_mod = TextDatumGetCString(DirectFunctionCall2(format_type, attr->atttypid, attr->atttypmod)); - elog(DEBUG1, "Adding typemodifier '%s' for column %d", typ_mod, natt); + elog(DEBUG1, "Adding typemodifier '%s' for column %d, optional %s", typ_mod, natt, !not_null ? "true" : "false"); typeinfo.modifier = typ_mod; + typeinfo.value_optional = !not_null; tmsg[valid_attr_cnt] = palloc(sizeof(typeinfo)); memcpy(tmsg[valid_attr_cnt], &typeinfo, sizeof(typeinfo)); diff --git a/src/proto/pg_logicaldec.pb-c.c b/src/proto/pg_logicaldec.pb-c.c index 98226e2..ea776f7 100644 --- a/src/proto/pg_logicaldec.pb-c.c +++ b/src/proto/pg_logicaldec.pb-c.c @@ -385,7 +385,7 @@ const ProtobufCMessageDescriptor decoderbufs__datum_message__descriptor = (ProtobufCMessageInit) decoderbufs__datum_message__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor decoderbufs__type_info__field_descriptors[1] = +static const ProtobufCFieldDescriptor decoderbufs__type_info__field_descriptors[2] = { { "modifier", @@ -399,14 +399,27 @@ static const ProtobufCFieldDescriptor decoderbufs__type_info__field_descriptors[ 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "value_optional", + 2, + PROTOBUF_C_LABEL_REQUIRED, + PROTOBUF_C_TYPE_BOOL, + 0, /* quantifier_offset */ + offsetof(Decoderbufs__TypeInfo, value_optional), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned decoderbufs__type_info__field_indices_by_name[] = { 0, /* field[0] = modifier */ + 1, /* field[1] = value_optional */ }; static const ProtobufCIntRange decoderbufs__type_info__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 1 } + { 0, 2 } }; const ProtobufCMessageDescriptor decoderbufs__type_info__descriptor = { @@ -416,7 +429,7 @@ const ProtobufCMessageDescriptor decoderbufs__type_info__descriptor = "Decoderbufs__TypeInfo", "decoderbufs", sizeof(Decoderbufs__TypeInfo), - 1, + 2, decoderbufs__type_info__field_descriptors, decoderbufs__type_info__field_indices_by_name, 1, decoderbufs__type_info__number_ranges, diff --git a/src/proto/pg_logicaldec.pb-c.h b/src/proto/pg_logicaldec.pb-c.h index 4e17513..fe7978f 100644 --- a/src/proto/pg_logicaldec.pb-c.h +++ b/src/proto/pg_logicaldec.pb-c.h @@ -82,10 +82,11 @@ struct _Decoderbufs__TypeInfo { ProtobufCMessage base; char *modifier; + protobuf_c_boolean value_optional; }; #define DECODERBUFS__TYPE_INFO__INIT \ { PROTOBUF_C_MESSAGE_INIT (&decoderbufs__type_info__descriptor) \ - , NULL } + , NULL, 0 } struct _Decoderbufs__RowMessage