This repository has been archived by the owner on Mar 28, 2024. It is now read-only.
forked from HearthSim/docker-pgredshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update json functions to more closely match Redshift, fixes HearthSim#3
Redshift returns NULL when a value cannot be found. Redshift strips quotes from strings returned in the JSON. Redshift checks for valid index when using json_extract_array_element_text.
- Loading branch information
Showing
2 changed files
with
31 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- These should work in Redshift and the docker container as of | ||
-- select version(); -- PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.34691 | ||
|
||
SELECT json_extract_array_element_text('[1,2,3]', -1); -- NULL | ||
SELECT json_extract_array_element_text('[1,2,3]', 0); -- 1 | ||
SELECT json_extract_array_element_text('[1,2,3]', 3); -- NULL | ||
SELECT json_extract_array_element_text('["a","b","c"]', -1); -- NULL | ||
SELECT json_extract_array_element_text('["a","b","c"]', 2); -- c | ||
SELECT json_extract_array_element_text('["a","b","c"]', 3); -- NULL | ||
|
||
-- Built in pg_catalog.json_extract_path_text exists so we need to include the schema when calling. | ||
-- See https://www.postgresql.org/docs/10/functions-json.html | ||
SELECT public.json_extract_path_text('{"a":{"b":{"c":1}},"d":[2,3],"e":"f"}', 'a'); -- {"b": {"c": 1}} | ||
SELECT public.json_extract_path_text('{"a":{"b":{"c":1}},"d":[2,3],"e":"f"}','a.b'); -- NULL | ||
SELECT public.json_extract_path_text('{"a":{"b":{"c":1}},"d":[2,3],"e":"f"}','d'); -- [2, 3] | ||
SELECT public.json_extract_path_text('{"a":{"b":{"c":1}},"d":[2,3],"e":"f"}','e'); -- f | ||
|
||
SELECT NOW(), getdate(); -- 2022-01-18 13:47:09.566 -0500, 2022-01-18 18:47:10.000 |