Skip to content

TypedValue(Type.jsonbArray, ...) cannot express NULL #449

@jonasfj

Description

@jonasfj

If you want to send [NULL, 'null', '{"key": "value"}']::jsonb[] to postgres there are means to do so.

I think the fix is the allow us to write:

TypedValue(
  Type.jsonbArray,
  [
     TypedValue(type.jsonbArray, null, isSqlNull: true), // NULL
     null,                                               // 'null'::jsonb
     {"key": "value"},                                   //'{"key": "value"}'::jsonb
  ],
  isSqlNull: false,
),

Probably, something we can fix in:

case TypeOid.jsonbArray:
{
if (input is List) {
final objectsArray = input
.map(_jsonFusedEncoding(encoding).encode)
.toList();
return _writeListBytes<List<int>>(
objectsArray,
3802,
(item) => item.length + 1,
(writer, item) {
writer.writeUint8(1);
writer.write(item);
},
encoding,
);
}
throw FormatException(
'Invalid type for parameter value. Expected: List Got: ${input.runtimeType}',
);
}

All we really need is a sentinel value that acts as SQL NULL, we probably don't even need to change anything we can just interpret TypedValue(type.jsonbArray, null, isSqlNull: true) as such sentinel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions