- 
                Notifications
    You must be signed in to change notification settings 
- Fork 326
Open
Description
I would expect null values in an array to end up as javascript nulls, just as they when a column is null in a row.
Here is a test demonstrating the handling of nulls in a "normal" query and what happens when array_agg is introduced.
    it.only('null values is array should be parsed as javascript nulls', async () => {
        await conn`
            CREATE TABLE test_nulls (
                id serial primary key,
                y text
            )
        `;
        await conn`
            insert into test_nulls (y) values
            ('a'), (null), ('b')
        `;
        
        const correct = await conn`
            SELECT
                y
            FROM test_nulls
        `;
        console.log(correct.map(r => r.y)); // [ 'a', null, 'b' ] <- actual null primitive
        expect(correct.find(r => r.y === null)).toBeDefined();
        const incorrect = await conn`
            SELECT
                array_agg(y)::text[] as y
            FROM test_nulls
        `;
        console.log(incorrect[0].y); // [ 'a', 'NULL', 'b' ] <-- string literal 'NULL'
        expect(incorrect[0].y.find(v => v === null)).toBeDefined();
    });
I could create a query helper as described in the Custom Types section of the README, but it's not clear how I would write a parser for an array. Especially considering that what appears to be the default (e.g., arrayParser() in the types.ts) file is rather complex; handling nested arrays, quotes, etc. I'm not sure I'm comfortable overriding that for what I would expect to be default behavior.
Metadata
Metadata
Assignees
Labels
No labels