Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion expected/message.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
6 changes: 6 additions & 0 deletions sql/message.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');
2 changes: 1 addition & 1 deletion wal2json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down