diff --git a/expected/message.out b/expected/message.out index dceacea..7269f34 100644 --- a/expected/message.out +++ b/expected/message.out @@ -70,6 +70,20 @@ SELECT 'msg10' FROM pg_logical_emit_message(true, 'wal2json', 'this is message # msg10 (1 row) +COMMIT; +SELECT 'msg11' FROM pg_logical_emit_message(false, 'wal2json', 'this message is outside of a transaction'); + ?column? +---------- + msg11 +(1 row) + +BEGIN; +SELECT 'msg12' FROM pg_logical_emit_message(true, 'wal2json', 'this message will be printed last'); + ?column? +---------- + msg12 +(1 row) + COMMIT; SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'pretty-print', '1'); data @@ -160,7 +174,27 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'pre } + ] + } -(8 rows) + { + + "change": [ + + { + + "kind": "message", + + "transactional": false, + + "prefix": "wal2json", + + "content": "this message is outside of a transaction" + + } + + ] + + } + { + + "change": [ + + { + + "kind": "message", + + "transactional": true, + + "prefix": "wal2json", + + "content": "this message will be printed last" + + } + + ] + + } +(10 rows) SELECT 'stop' FROM pg_drop_replication_slot('regression_slot'); ?column? diff --git a/sql/message.sql b/sql/message.sql index ebaa5fe..1754085 100644 --- a/sql/message.sql +++ b/sql/message.sql @@ -23,6 +23,12 @@ SELECT 'msg9' FROM pg_logical_emit_message(false, 'wal2json', 'this message will SELECT 'msg10' FROM pg_logical_emit_message(true, 'wal2json', 'this is message #2'); COMMIT; +SELECT 'msg11' FROM pg_logical_emit_message(false, 'wal2json', 'this message is outside of a transaction'); + +BEGIN; +SELECT 'msg12' FROM pg_logical_emit_message(true, 'wal2json', 'this message will be printed last'); +COMMIT; + SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'pretty-print', '1'); SELECT 'stop' FROM pg_drop_replication_slot('regression_slot'); diff --git a/wal2json.c b/wal2json.c index 53a933f..a7793ef 100644 --- a/wal2json.c +++ b/wal2json.c @@ -1040,7 +1040,7 @@ pg_decode_message(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, appendStringInfo(ctx->out, "%s%s", data->ht, data->ht); - if (data->nr_changes > 1) + if (transactional && data->nr_changes > 1) appendStringInfoChar(ctx->out, ','); appendStringInfo(ctx->out, "{%s%s%s%s\"kind\":%s\"message\",%s", data->nl, data->ht, data->ht, data->ht, data->sp, data->nl);