From be18d757ed01521f4afbd2b6d72c593a87b0d0c7 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Wed, 28 Oct 2026 08:57:48 +0100 Subject: [PATCH] Fix empty array parsing --- src/protocol.ts | 4 +++- test/result.test.ts | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/protocol.ts b/src/protocol.ts index b55e7e1..7cf8146 100644 --- a/src/protocol.ts +++ b/src/protocol.ts @@ -512,7 +512,9 @@ export function readRowData( offset += 4; - if (dimCount === 0) { + if (dimCount < 0) { + value = []; + } else if (dimCount === 0) { const size = buffer.readInt32BE(offset); offset += 8; value = readArray(size); diff --git a/test/result.test.ts b/test/result.test.ts index 37b06c9..86bd7fb 100644 --- a/test/result.test.ts +++ b/test/result.test.ts @@ -77,6 +77,11 @@ describe('Result', () => { deepEqual(row.a, [null]); }); + test('Parse empty array', async ({ client }) => { + const row = await client.query("select '{}'::text[] as a").one(); + deepEqual(row.a, []); + }); + test('Format array containing null value', async ({ client }) => { const row = await client .query('select $1::text[] as a', [[null]])