diff options
author | Joey Adams | 2011-01-17 20:43:57 +0000 |
---|---|---|
committer | Joey Adams | 2011-01-17 20:47:27 +0000 |
commit | 97e50382f3ccc7f452a6ae402c824d3e5df3d4d8 (patch) | |
tree | 5472672e8872c5b5bfe7153bcaf5598b19d161fb | |
parent | abf3ee001d49afec5b5138b48b460c137f27cbc5 (diff) |
Added PostgreSQL 8.4.3 compatibility.
The SearchSysCacheList1 macro was introduced in PostgreSQL 9.
Changed a couple tests to cope with formatting discrepancy
introduced by PostgreSQL 9 (namely, + characters between newlines).
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | compat.c | 14 | ||||
-rw-r--r-- | compat.h | 22 | ||||
-rw-r--r-- | expected/json.out | 11 | ||||
-rw-r--r-- | expected/json_path.out | 628 | ||||
-rw-r--r-- | sql/json.sql | 5 | ||||
-rw-r--r-- | sql/json_path.sql | 6 | ||||
-rw-r--r-- | util.c | 2 |
8 files changed, 342 insertions, 348 deletions
@@ -1,5 +1,5 @@ MODULE_big = json -OBJS = json.o jsonpath.o json_io.o json_op.o util.o +OBJS = json.o jsonpath.o json_io.o json_op.o util.o compat.o DATA_built = json.sql DATA = uninstall_json.sql diff --git a/compat.c b/compat.c new file mode 100644 index 0000000..aa1fd39 --- /dev/null +++ b/compat.c @@ -0,0 +1,14 @@ +/*------------------------------------------------------------------------- + * + * compat.c + * Compatibility routines to let the JSON module work in PostgreSQL 8.3 + * + * Copyright (c) 2011, PostgreSQL Global Development Group + * Arranged by Joey Adams <[email protected]>. + * + *------------------------------------------------------------------------- + */ + +#include "compat.h" + + diff --git a/compat.h b/compat.h new file mode 100644 index 0000000..3c9421b --- /dev/null +++ b/compat.h @@ -0,0 +1,22 @@ +/*------------------------------------------------------------------------- + * + * compat.h + * Compatibility routines to let the JSON module work in PostgreSQL 8.3 + * + * Copyright (c) 2011, PostgreSQL Global Development Group + * Arranged by Joey Adams <[email protected]>. + * + *------------------------------------------------------------------------- + */ + +#ifndef JSON_COMPAT_H +#define JSON_COMPAT_H + +/*** 8.4.3 ***/ + +#ifndef SearchSysCacheList1 + #define SearchSysCacheList1(cacheId, key1) \ + SearchSysCacheList(cacheId, 1, key1, 0, 0, 0) +#endif + +#endif diff --git a/expected/json.out b/expected/json.out index 63e7633..9b18b5f 100644 --- a/expected/json.out +++ b/expected/json.out @@ -475,13 +475,14 @@ SELECT from_json('"valid string"'); valid string (1 row) +-- Use unaligned output so results are consistent between PostgreSQL 8 and 9. +\a SELECT from_json($$ "hello\nworld" $$); - from_json ------------ - hello + - world +from_json +hello +world (1 row) - +\a SELECT from_json($$ "hello\u0000world" $$); ERROR: could not convert JSON-encoded string to TEXT: contains \u0000 DETAIL: the string was: "hello\u0000world" diff --git a/expected/json_path.out b/expected/json_path.out index 22c0f10..931c4ee 100644 --- a/expected/json_path.out +++ b/expected/json_path.out @@ -645,405 +645,349 @@ INSERT INTO sample VALUES ($$ } } $$); +-- Use unaligned output so results are consistent between PostgreSQL 8 and 9. +\a SELECT json_path(json, 'store.books[*]') FROM sample; - json_path -------------------------------------------------------- - { + - "title": "book 0", + - "author": "author 0",+ - "prices": [1,2,3] + - } - { + - "title": "book 1", + - "author": "author 1",+ - "prices": [4,5,6] + - } - { + - "title": "book 2", + - "author": "author 2",+ - "prices": [7,8,9] + - } +json_path +{ + "title": "book 0", + "author": "author 0", + "prices": [1,2,3] + } +{ + "title": "book 1", + "author": "author 1", + "prices": [4,5,6] + } +{ + "title": "book 2", + "author": "author 2", + "prices": [7,8,9] + } (3 rows) - SELECT json_path(json, 'store.books[*].title') FROM sample; - json_path ------------ - "book 0" - "book 1" - "book 2" +json_path +"book 0" +"book 1" +"book 2" (3 rows) - SELECT json_path(json, 'store.books[*].author') FROM sample; - json_path ------------- - "author 0" - "author 1" - "author 2" +json_path +"author 0" +"author 1" +"author 2" (3 rows) - SELECT json_path(json, 'store.books[*].prices') FROM sample; - json_path ------------ - [1,2,3] - [4,5,6] - [7,8,9] +json_path +[1,2,3] +[4,5,6] +[7,8,9] (3 rows) - SELECT json_path(json, 'store.books[*].prices[*]') FROM sample; - json_path ------------ - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 +json_path +1 +2 +3 +4 +5 +6 +7 +8 +9 (9 rows) - SELECT json_path(json, 'store.toys[*]') FROM sample; - json_path --------------- - "Yo-yo" - "Boomerang" - "Basketball" +json_path +"Yo-yo" +"Boomerang" +"Basketball" (3 rows) - SELECT json_path(json, 'store.toys[*][0]') FROM sample; - json_path ------------ +json_path (0 rows) - SELECT json_path(json, 'store.toys[*][1]') FROM sample; - json_path ------------ +json_path (0 rows) - SELECT json_path(json, 'store.toys[*][0][0]') FROM sample; - json_path ------------ +json_path (0 rows) - SELECT json_path(json, 'store.toys[*][0][1]') FROM sample; - json_path ------------ +json_path (0 rows) - SELECT json_path(json, '..books') FROM sample; - json_path -------------------------------------------------------- - [ + - { + - "title": "book 0", + - "author": "author 0",+ - "prices": [1,2,3] + - }, { + - "title": "book 1", + - "author": "author 1",+ - "prices": [4,5,6] + - }, { + - "title": "book 2", + - "author": "author 2",+ - "prices": [7,8,9] + - } + - ] +json_path +[ + { + "title": "book 0", + "author": "author 0", + "prices": [1,2,3] + }, { + "title": "book 1", + "author": "author 1", + "prices": [4,5,6] + }, { + "title": "book 2", + "author": "author 2", + "prices": [7,8,9] + } + ] (1 row) - SELECT json_path(json, '..books[*]') FROM sample; - json_path -------------------------------------------------------- - { + - "title": "book 0", + - "author": "author 0",+ - "prices": [1,2,3] + - } - { + - "title": "book 1", + - "author": "author 1",+ - "prices": [4,5,6] + - } - { + - "title": "book 2", + - "author": "author 2",+ - "prices": [7,8,9] + - } +json_path +{ + "title": "book 0", + "author": "author 0", + "prices": [1,2,3] + } +{ + "title": "book 1", + "author": "author 1", + "prices": [4,5,6] + } +{ + "title": "book 2", + "author": "author 2", + "prices": [7,8,9] + } (3 rows) - SELECT json_path(json, '..title') FROM sample; - json_path ------------ - "book 0" - "book 1" - "book 2" +json_path +"book 0" +"book 1" +"book 2" (3 rows) - SELECT json_path(json, '..author') FROM sample; - json_path ------------- - "author 0" - "author 1" - "author 2" +json_path +"author 0" +"author 1" +"author 2" (3 rows) - SELECT json_path(json, '..prices[*]') FROM sample; - json_path ------------ - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 +json_path +1 +2 +3 +4 +5 +6 +7 +8 +9 (9 rows) - SELECT json_path(json, '..toys[*]') FROM sample; - json_path --------------- - "Yo-yo" - "Boomerang" - "Basketball" +json_path +"Yo-yo" +"Boomerang" +"Basketball" (3 rows) - SELECT json_path(json, '..toys..[*]') FROM sample; - json_path --------------- - "Yo-yo" - "Boomerang" - "Basketball" +json_path +"Yo-yo" +"Boomerang" +"Basketball" (3 rows) - SELECT json_path(json, '..[-1]') FROM sample; - json_path ------------ +json_path (0 rows) - SELECT json_path(json, '..[0]') FROM sample; - json_path -------------------------------------------------------- - { + - "title": "book 0", + - "author": "author 0",+ - "prices": [1,2,3] + - } - 1 - 4 - 7 - "Yo-yo" +json_path +{ + "title": "book 0", + "author": "author 0", + "prices": [1,2,3] + } +1 +4 +7 +"Yo-yo" (5 rows) - SELECT json_path(json, '..[1]') FROM sample; - json_path -------------------------------------------------------- - { + - "title": "book 1", + - "author": "author 1",+ - "prices": [4,5,6] + - } - 2 - 5 - 8 - "Boomerang" +json_path +{ + "title": "book 1", + "author": "author 1", + "prices": [4,5,6] + } +2 +5 +8 +"Boomerang" (5 rows) - SELECT json_path(json, '..[2]') FROM sample; - json_path -------------------------------------------------------- - { + - "title": "book 2", + - "author": "author 2",+ - "prices": [7,8,9] + - } - 3 - 6 - 9 - "Basketball" +json_path +{ + "title": "book 2", + "author": "author 2", + "prices": [7,8,9] + } +3 +6 +9 +"Basketball" (5 rows) - SELECT json_path(json, '..[3]') FROM sample; - json_path ------------ +json_path (0 rows) - SELECT json_path(json, '$') FROM sample; - json_path -------------------------------------------------------- - { + - "store": { + - "books": [ + - { + - "title": "book 0", + - "author": "author 0",+ - "prices": [1,2,3] + - }, { + - "title": "book 1", + - "author": "author 1",+ - "prices": [4,5,6] + - }, { + - "title": "book 2", + - "author": "author 2",+ - "prices": [7,8,9] + - } + - ], + - "toys": [ + - "Yo-yo", + - "Boomerang", + - "Basketball" + - ] + - } + - } +json_path +{ + "store": { + "books": [ + { + "title": "book 0", + "author": "author 0", + "prices": [1,2,3] + }, { + "title": "book 1", + "author": "author 1", + "prices": [4,5,6] + }, { + "title": "book 2", + "author": "author 2", + "prices": [7,8,9] + } + ], + "toys": [ + "Yo-yo", + "Boomerang", + "Basketball" + ] + } +} (1 row) - SELECT json_path(json, '..*') FROM sample; - json_path -------------------------------------------------------- - { + - "books": [ + - { + - "title": "book 0", + - "author": "author 0",+ - "prices": [1,2,3] + - }, { + - "title": "book 1", + - "author": "author 1",+ - "prices": [4,5,6] + - }, { + - "title": "book 2", + - "author": "author 2",+ - "prices": [7,8,9] + - } + - ], + - "toys": [ + - "Yo-yo", + - "Boomerang", + - "Basketball" + - ] + - } - [ + - { + - "title": "book 0", + - "author": "author 0",+ - "prices": [1,2,3] + - }, { + - "title": "book 1", + - "author": "author 1",+ - "prices": [4,5,6] + - }, { + - "title": "book 2", + - "author": "author 2",+ - "prices": [7,8,9] + - } + - ] - [ + - "Yo-yo", + - "Boomerang", + - "Basketball" + - ] - { + - "title": "book 0", + - "author": "author 0",+ - "prices": [1,2,3] + - } - { + - "title": "book 1", + - "author": "author 1",+ - "prices": [4,5,6] + - } - { + - "title": "book 2", + - "author": "author 2",+ - "prices": [7,8,9] + - } - "book 0" - "author 0" - [1,2,3] - 1 - 2 - 3 - "book 1" - "author 1" - [4,5,6] - 4 - 5 - 6 - "book 2" - "author 2" - [7,8,9] - 7 - 8 - 9 - "Yo-yo" - "Boomerang" - "Basketball" +json_path +{ + "books": [ + { + "title": "book 0", + "author": "author 0", + "prices": [1,2,3] + }, { + "title": "book 1", + "author": "author 1", + "prices": [4,5,6] + }, { + "title": "book 2", + "author": "author 2", + "prices": [7,8,9] + } + ], + "toys": [ + "Yo-yo", + "Boomerang", + "Basketball" + ] + } +[ + { + "title": "book 0", + "author": "author 0", + "prices": [1,2,3] + }, { + "title": "book 1", + "author": "author 1", + "prices": [4,5,6] + }, { + "title": "book 2", + "author": "author 2", + "prices": [7,8,9] + } + ] +[ + "Yo-yo", + "Boomerang", + "Basketball" + ] +{ + "title": "book 0", + "author": "author 0", + "prices": [1,2,3] + } +{ + "title": "book 1", + "author": "author 1", + "prices": [4,5,6] + } +{ + "title": "book 2", + "author": "author 2", + "prices": [7,8,9] + } +"book 0" +"author 0" +[1,2,3] +1 +2 +3 +"book 1" +"author 1" +[4,5,6] +4 +5 +6 +"book 2" +"author 2" +[7,8,9] +7 +8 +9 +"Yo-yo" +"Boomerang" +"Basketball" (27 rows) - SELECT json_path(json, '..char(-1)') FROM sample; - json_path ------------ +json_path (0 rows) - SELECT json_path(json, '..char(0)') FROM sample; - json_path ------------ - "b" - "a" - "b" - "a" - "b" - "a" - "Y" - "B" - "B" +json_path +"b" +"a" +"b" +"a" +"b" +"a" +"Y" +"B" +"B" (9 rows) - SELECT json_path(json, '..char(1)') FROM sample; - json_path ------------ - "o" - "u" - "o" - "u" - "o" - "u" - "o" - "o" - "a" +json_path +"o" +"u" +"o" +"u" +"o" +"u" +"o" +"o" +"a" (9 rows) - SELECT json_path(json, '..char(2)') FROM sample; - json_path ------------ - "o" - "t" - "o" - "t" - "o" - "t" - "-" - "o" - "s" +json_path +"o" +"t" +"o" +"t" +"o" +"t" +"-" +"o" +"s" (9 rows) - SELECT json_path(json, '..char(3)') FROM sample; - json_path ------------ - "k" - "h" - "k" - "h" - "k" - "h" - "y" - "m" - "k" +json_path +"k" +"h" +"k" +"h" +"k" +"h" +"y" +"m" +"k" (9 rows) - SELECT json_path(json, '..char(100)') FROM sample; - json_path ------------ +json_path (0 rows) - +-- Turn aligned output back on. +\a diff --git a/sql/json.sql b/sql/json.sql index 1e98d6c..526c881 100644 --- a/sql/json.sql +++ b/sql/json.sql @@ -114,7 +114,12 @@ SELECT from_json(NULL::JSON); -- from_json: string SELECT from_json('"valid string"'); + +-- Use unaligned output so results are consistent between PostgreSQL 8 and 9. +\a SELECT from_json($$ "hello\nworld" $$); +\a + SELECT from_json($$ "hello\u0000world" $$); -- from_json: number diff --git a/sql/json_path.sql b/sql/json_path.sql index 01d972b..0974a28 100644 --- a/sql/json_path.sql +++ b/sql/json_path.sql @@ -137,6 +137,9 @@ INSERT INTO sample VALUES ($$ } $$); +-- Use unaligned output so results are consistent between PostgreSQL 8 and 9. +\a + SELECT json_path(json, 'store.books[*]') FROM sample; SELECT json_path(json, 'store.books[*].title') FROM sample; SELECT json_path(json, 'store.books[*].author') FROM sample; @@ -171,3 +174,6 @@ SELECT json_path(json, '..char(1)') FROM sample; SELECT json_path(json, '..char(2)') FROM sample; SELECT json_path(json, '..char(3)') FROM sample; SELECT json_path(json, '..char(100)') FROM sample; + +-- Turn aligned output back on. +\a @@ -15,6 +15,8 @@ #include "catalog/pg_enum.h" #include "utils/syscache.h" +#include "compat.h" + /* * getTypeInfo * Retrieve information about a type, along with either its |