Repository navigation
Parse NULL elements in arrays as null - #1258
Open
OsamaAnsar wants to merge 1 commit into
Open
OsamaAnsar wants to merge 1 commit into
OsamaAnsar wants to merge 1 commit into
Conversation
An unquoted NULL in array output was handed to the element parser like any other value, so it came out as the string 'NULL' for text, NaN for int2/int4, false for bool and Invalid Date for dates, and made json/jsonb arrays throw. Postgres quotes a string that reads NULL, so an unquoted NULL is always a null element and is now returned as null without calling the element parser.
|
Any reason this does not get merged? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1049, fixes #1124.
An unquoted
NULLelement in array output was passed to the element parser like any other value. Depending on the element type that gave:array['a', null, 'b']::text[]['a', 'NULL', 'b']['a', null, 'b']array[1, null]::int2[][1, NaN][1, null]array[1.5, null]::numeric[]['1.5', 'NULL']['1.5', null]array[true, null]::bool[][true, false][true, null]array['{"a":1}'::json, null]"NULL" is not valid JSON[{ a: 1 }, null]array[1, null]::bigint[]['1', 'NULL']['1', null]array['2020-01-01 00:00:00+00'::timestamptz, null][Date, Invalid Date][Date, null]array_agg(y)over'a', null, 'b'['a', 'NULL', 'b']['a', null, 'b']array[[1, null], [null, 4]]::int[][[1, NaN], [NaN, 4]][[1, null], [null, 4]]This is the same behaviour as a
NULLcolumn value, which already comes back asnullwithout going through the parser, and it matches whatsql.array([1, null, 3])already sends on the write side.Postgres always quotes a string that reads
NULL(in any case) in array output, so the unquoted token is unambiguous. The three places inarrayParserLoopthat push an unquoted slice now go through a smallarrayElementhelper that returnsnullfor the bareNULLtoken and otherwise behaves as before. Quoted elements are untouched, soarray['NULL', null]::text[]gives['NULL', null].Notes:
types) is no longer called for aNULLelement, so a custom parser will not see the string'NULL'any more.[0:2]={...}is unchanged apart from theNULLelements.Tests
Added 16 tests to
tests/index.js: end to end queries for text, int2/int4, bigint, numeric, bool, timestamptz, json,array_agg, nested arrays, an array of only nulls, a real'NULL'string (plain, nested and round tripped throughsql.array), a custom type parser that must not receiveNULL, and directarrayParsercalls (including the;delimited box type). Without thesrc/types.jschange every one of them fails, and with it they all pass.What I ran
tests/index.jswas not run, because it needs a real server withpsql/createdb, so I can't say anything about the other tests here.eslint src testspasses (eslint 8 with the repo's.eslintrc.json).transpile.cjs,transpile.deno.jsandtranspile.cf.jssucceed on a copy of the tree and that the transpiled test file for cjs passesnode --check. I did not commit thecjs/,deno/orcf/output, since those look to be rebuilt in separate build commits.Several open PRs touch
src/types.js(e.g. #1247, #1162, #392), but none of their diffs toucharrayParserLoop, so I don't expect conflicts.