diff options
| author | Joey Adams | 2010-07-14 04:45:34 +0000 |
|---|---|---|
| committer | Joey Adams | 2010-07-14 04:45:34 +0000 |
| commit | abf3491883d45ce492c1d1a06c3fd01c2e8f90d8 (patch) | |
| tree | 88c799f158cfc928ea63ca8f7804dd62ae55ef5c | |
| parent | 6580672c67a36b841663f7eb490d1eb8f965513f (diff) | |
Changed json_get so it no longer automatically applies from_json.
Although automatic from_json may be convenient in some cases, it would require
introducing an extra pair of functions (e.g. json_get_json and json_set_json)
that work with JSON rather than converted JSON. Unless
from_json(json_get(...)) turns out to be by far the most common usage pattern,
I think knocking out the conversion wrapping here makes a lot more sense.
| -rw-r--r-- | expected/json_get.out | 4 | ||||
| -rw-r--r-- | json.sql.in | 6 | ||||
| -rw-r--r-- | json_op.c | 4 |
3 files changed, 6 insertions, 8 deletions
diff --git a/expected/json_get.out b/expected/json_get.out index 959b671..b297241 100644 --- a/expected/json_get.out +++ b/expected/json_get.out @@ -1,7 +1,7 @@ SELECT json_get('{"key": "value", "key2": "value2"}', 'key'); json_get ---------- - value + "value" (1 row) SELECT json_get('{"key": "value", "key": "value2"}', 'key'); @@ -30,7 +30,7 @@ SELECT json_get('{"0": "value", "0": "value"}', '.0'); SELECT json_get('{"0": "value", "1": "value"}', '["0"]'); json_get ---------- - value + "value" (1 row) SELECT json_get('{"0": "value", "0": "value"}', '["0"]'); diff --git a/json.sql.in b/json.sql.in index 08c3c9a..36aa6cf 100644 --- a/json.sql.in +++ b/json.sql.in @@ -60,12 +60,12 @@ AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE; -- not STRICT; allows to_json(NULL) to return 'null'::json. CREATE OR REPLACE FUNCTION json_get(json, json_path text) -RETURNS text +RETURNS json AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; /* -CREATE OR REPLACE FUNCTION json_set(json, json_path text, text) -RETURNS text +CREATE OR REPLACE FUNCTION json_set(json, json_path text, json) +RETURNS json AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; */ @@ -108,7 +108,6 @@ json_get(PG_FUNCTION_ARGS) List *result_list = json_path_base(fcinfo, "json_get"); ListCell *result; const char *rs_json; - const char *rs_text; jsontype *result_vardata; int length = list_length(result_list); @@ -121,8 +120,7 @@ json_get(PG_FUNCTION_ARGS) Assert(rs_json != NULL); Assert(json_validate(rs_json) == true); - rs_text = from_json_cstring(rs_json, "json_get"); - result_vardata = (jsontype*) cstring_to_text(rs_text); + result_vardata = (jsontype*) cstring_to_text(rs_json); PG_RETURN_JSON_P(result_vardata); } else { |
