From: | Markus Winand <markus(dot)winand(at)winand(dot)at> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | SQL/JSON path: collation for comparisons, minor typos in docs |
Date: | 2019-08-07 11:25:36 |
Message-ID: | 8B7FA3B4-328D-43D7-95A8-37B8891B8C78@winand.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi!
I was playing around with JSON path quite a bit and might have found one case where the current implementation doesn’t follow the standard.
The functionality in question are the comparison operators except ==. They use the database default collation rather then the standard-mandated "Unicode codepoint collation” (SQL-2:2016 9.39 General Rule 12 c iii 2 D, last sentence in first paragraph).
I guess this is the relevant part of the code: src/backend/utils/adt/jsonpath_exec.c (compareItems)
case jbvString:
if (op == jpiEqual)
return jb1->val.string.len != jb2->val.string.len ||
memcmp(jb1->val.string.val,
jb2->val.string.val,
jb1->val.string.len) ? jpbFalse : jpbTrue;
cmp = varstr_cmp(jb1->val.string.val, jb1->val.string.len,
jb2->val.string.val, jb2->val.string.len,
DEFAULT_COLLATION_OID);
break;
Testcase:
postgres 12beta3=# select * from jsonb_path_query('"dummy"', '$ ? ("a" < "A")');
jsonb_path_query
------------------
"dummy"
(1 row)
In code points, lower case ‘a' is not less than upper case ‘A’—the result should be empty.
To convince myself:
postgres 12beta3=# select datcollate, 'a' < 'A', 'a' <'A' COLLATE ucs_basic from pg_database where datname=current_database();
datcollate | ?column? | ?column?
-------------+----------+----------
en_US.UTF-8 | t | f
(1 row)
I also found two minor typos in the docs. Patch attached.
-markus
ps.: I’ve created 230 test cases. Besides the WIP topic .datetime(), the collation issue is the only one I found. Excellent work. Down to the SQLSTATEs. For sure the most complete and correct SQL/JSON path implementation I've seen.
Attachment | Content-Type | Size |
---|---|---|
0001-Doc-Fix-typos-in-json-path-documentation.patch | application/octet-stream | 1.3 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Heikki Linnakangas | 2019-08-07 11:28:06 | Grouping isolationtester tests in the schedule |
Previous Message | Bruce Momjian | 2019-08-07 11:19:11 | Re: [Proposal] Table-level Transparent Data Encryption (TDE) and Key Management Service (KMS) |