Skip to content

Errors and inconsistencies handling of null values in arrays #28

@njhartwell

Description

@njhartwell

As a basic example,

SELECT NULL returns {{select,1},[{null}]}
but SELECT array[NULL, NULL]::varchar[] returns {{select,1},[{{array,[<<"NULL">>]}}]}

Another one:
select ARRAY['2014-01-01T12:12:12Z', NULL]::timestamp[]; will crash the process with

{{badmatch,{error,{fread,unsigned}}},[{pgsql_protocol,decode_value_text,3,[{file,"src/pgsql_protocol.erl"},{line,813}]},{pgsql_protocol,decode_array_text,4,[{file,"src/pgsql_protocol.erl"},{line,940}]},{pgsql_protocol,decode_array_text

The actual use case where I came across this was with two similar queries (the only difference is the where clause):

SELECT
            uuid,
            start_time,
            end_time,
            state,
            phone_number,
            direction,
            agent,
            array_agg(code) as wrap_up_codes,
            queue,
            array_agg(skill) as skills
        FROM phone_call
        LEFT JOIN phone_call_skill on phone_call.id=phone_call_skill.phone_call_id
        LEFT JOIN phone_call_wrap_up_code on phone_call.id=phone_call_wrap_up_code.phone_call_id GROUP BY id ORDER BY start_time DESC LIMIT 1

Returns
[{<<"73a13a1f5d78697568a4fd58031aa6ea3b30ce43">>,{{2015,5,13},{19,24,55}},null,<<"waiting">>,<<"5552221111">>,{call_direction,<<"inbound">>},null,{array,[<<"NULL">>]},<<"appointment">>,{array,[<<"NULL">>]}}]

whereas

SELECT
            uuid,
            start_time,
            end_time,
            state,
            phone_number,
            direction,
            agent,
            array_agg(code) as wrap_up_codes,
            queue,
            array_agg(skill) as skills
        FROM phone_call
        LEFT JOIN phone_call_skill on phone_call.id=phone_call_skill.phone_call_id
        LEFT JOIN phone_call_wrap_up_code on phone_call.id=phone_call_wrap_up_code.phone_call_id WHERE uuid = $1 GROUP BY id ORDER BY start_time DESC LIMIT 1

Returns [{<<"73a13a1f5d78697568a4fd58031aa6ea3b30ce43">>,{{2015,5,13},{19,24,55}},null,<<"waiting">>,<<"5552221111">>,{call_direction,<<"inbound">>},null,{array,[null]},<<"appointment">>,{array,[null]}}]

Thanks!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions