summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Adams2011-03-26 18:37:20 +0000
committerJoey Adams2011-03-26 19:19:00 +0000
commit9ff7dd81c8eea6dde24e786e2b27c76f319e5b34 (patch)
tree58290ea6f18b2ecc49e9a943e0a7f637f4603a31
parent59b46ebff2133b363ae3b174714726cf1c8640a4 (diff)
Remove json_send/json_recv and rename json_type/json_type_t to json_get_type/json_type
-rw-r--r--documentation4
-rw-r--r--expected/json.out148
-rw-r--r--json.sgml6
-rw-r--r--json.sql.in20
-rw-r--r--json_io.c46
-rw-r--r--json_op.c2
-rw-r--r--sql/json.sql56
-rw-r--r--uninstall_json.sql2
8 files changed, 113 insertions, 171 deletions
diff --git a/documentation b/documentation
index 217a32c..b9a63b5 100644
--- a/documentation
+++ b/documentation
@@ -32,5 +32,5 @@ json_condense(json) -> json: Re-encodes JSON to form a string with minimal lengt
json_condense(' { "key" : "value"} ') => '{"key":"value"}'
json_condense($$ "\u266B" $$) => '"♫"' -- if encoding supports Unicode
-json_type(json) -> json_type_t {'null' | 'string' | 'number' | 'bool' | 'object' | 'array'}: Get the type of a <type>json</type> value.
- json_type('{"pi": "3.14159", "e": "2.71828"}') => 'object'
+json_get_type(json) -> json_type {'null' | 'string' | 'number' | 'bool' | 'object' | 'array'}: Get the type of a <type>json</type> value.
+ json_get_type('{"pi": "3.14159", "e": "2.71828"}') => 'object'
diff --git a/expected/json.out b/expected/json.out
index 9b18b5f..015d604 100644
--- a/expected/json.out
+++ b/expected/json.out
@@ -98,33 +98,33 @@ SELECT 15::JSON;
15
(1 row)
-SELECT json_type('[]');
- json_type
------------
+SELECT json_get_type('[]');
+ json_get_type
+---------------
array
(1 row)
-SELECT json_type('{}');
- json_type
------------
+SELECT json_get_type('{}');
+ json_get_type
+---------------
object
(1 row)
-SELECT json_type('true');
- json_type
------------
+SELECT json_get_type('true');
+ json_get_type
+---------------
bool
(1 row)
-SELECT json_type('false');
- json_type
------------
+SELECT json_get_type('false');
+ json_get_type
+---------------
bool
(1 row)
-SELECT json_type('null');
- json_type
------------
+SELECT json_get_type('null');
+ json_get_type
+---------------
null
(1 row)
@@ -158,9 +158,9 @@ SELECT * FROM testjson;
{}
(8 rows)
-SELECT json_type(j) FROM testjson;
- json_type
------------
+SELECT json_get_type(j) FROM testjson;
+ json_get_type
+---------------
array
object
string
@@ -196,26 +196,26 @@ SELECT to_json('null'::text); -- should yield '"null"', not 'null'
"null"
(1 row)
-SELECT json_type(to_json(NULL));
+SELECT json_get_type(to_json(NULL));
ERROR: could not determine polymorphic type because input has type "unknown"
-SELECT json_type(to_json(NULL::INT));
- json_type
------------
+SELECT json_get_type(to_json(NULL::INT));
+ json_get_type
+---------------
null
(1 row)
-SELECT json_type(to_json(NULL::VOID));
+SELECT json_get_type(to_json(NULL::VOID));
ERROR: to_json cannot convert void to JSON
-SELECT json_type(to_json(NULL::MONEY));
+SELECT json_get_type(to_json(NULL::MONEY));
ERROR: to_json cannot convert money to JSON
-- to_json: string
SELECT to_json('');
ERROR: could not determine polymorphic type because input has type "unknown"
-SELECT json_type(to_json(''));
+SELECT json_get_type(to_json(''));
ERROR: could not determine polymorphic type because input has type "unknown"
SELECT to_json('string');
ERROR: could not determine polymorphic type because input has type "unknown"
-SELECT json_type(to_json('string'));
+SELECT json_get_type(to_json('string'));
ERROR: could not determine polymorphic type because input has type "unknown"
SELECT to_json('string'::VARCHAR);
to_json
@@ -223,9 +223,9 @@ SELECT to_json('string'::VARCHAR);
"string"
(1 row)
-SELECT json_type(to_json('string'::VARCHAR));
- json_type
------------
+SELECT json_get_type(to_json('string'::VARCHAR));
+ json_get_type
+---------------
string
(1 row)
@@ -235,9 +235,9 @@ SELECT to_json('string'::VARCHAR(3));
"str"
(1 row)
-SELECT json_type(to_json('string'::VARCHAR(3)));
- json_type
------------
+SELECT json_get_type(to_json('string'::VARCHAR(3)));
+ json_get_type
+---------------
string
(1 row)
@@ -247,9 +247,9 @@ SELECT to_json('{1,2,3}'::TEXT);
"{1,2,3}"
(1 row)
-SELECT json_type(to_json('{1,2,3}'::TEXT));
- json_type
------------
+SELECT json_get_type(to_json('{1,2,3}'::TEXT));
+ json_get_type
+---------------
string
(1 row)
@@ -259,9 +259,9 @@ SELECT to_json('"doubly-encoded"'::JSON);
"\"doubly-encoded\""
(1 row)
-SELECT json_type(to_json('"doubly-encoded"'::JSON));
- json_type
------------
+SELECT json_get_type(to_json('"doubly-encoded"'::JSON));
+ json_get_type
+---------------
string
(1 row)
@@ -271,9 +271,9 @@ SELECT to_json('"nested quotes"'::TEXT);
"\"nested quotes\""
(1 row)
-SELECT json_type(to_json('"nested quotes"'::TEXT));
- json_type
------------
+SELECT json_get_type(to_json('"nested quotes"'::TEXT));
+ json_get_type
+---------------
string
(1 row)
@@ -283,9 +283,9 @@ SELECT to_json('"nested quotes"'::TEXT)::TEXT::JSON;
"\"nested quotes\""
(1 row)
-SELECT json_type(to_json('"nested quotes"'::TEXT)::TEXT::JSON);
- json_type
------------
+SELECT json_get_type(to_json('"nested quotes"'::TEXT)::TEXT::JSON);
+ json_get_type
+---------------
string
(1 row)
@@ -295,9 +295,9 @@ SELECT to_json('h'::CHAR);
"h"
(1 row)
-SELECT json_type(to_json('h'::CHAR));
- json_type
------------
+SELECT json_get_type(to_json('h'::CHAR));
+ json_get_type
+---------------
string
(1 row)
@@ -307,9 +307,9 @@ SELECT to_json('hello world'::CHAR);
"h"
(1 row)
-SELECT json_type(to_json('hello world'::CHAR));
- json_type
------------
+SELECT json_get_type(to_json('hello world'::CHAR));
+ json_get_type
+---------------
string
(1 row)
@@ -319,9 +319,9 @@ SELECT to_json('hello world!'::CHAR(11));
"hello world"
(1 row)
-SELECT json_type(to_json('hello world!'::CHAR(11)));
- json_type
------------
+SELECT json_get_type(to_json('hello world!'::CHAR(11)));
+ json_get_type
+---------------
string
(1 row)
@@ -338,15 +338,15 @@ SELECT to_json(12345.678);
12345.678
(1 row)
-SELECT json_type(to_json(12345));
- json_type
------------
+SELECT json_get_type(to_json(12345));
+ json_get_type
+---------------
number
(1 row)
-SELECT json_type(to_json(12345.678));
- json_type
------------
+SELECT json_get_type(to_json(12345.678));
+ json_get_type
+---------------
number
(1 row)
@@ -368,9 +368,9 @@ SELECT to_json(123456789012345678901234567890123456789012345678901234567890.1234
123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890123456789012345678901234567890
(1 row)
-SELECT json_type(to_json(123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890123456789012345678901234567890));
- json_type
------------
+SELECT json_get_type(to_json(123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890123456789012345678901234567890));
+ json_get_type
+---------------
number
(1 row)
@@ -401,27 +401,27 @@ SELECT to_json(1=2);
false
(1 row)
-SELECT json_type(to_json(TRUE));
- json_type
------------
+SELECT json_get_type(to_json(TRUE));
+ json_get_type
+---------------
bool
(1 row)
-SELECT json_type(to_json(FALSE));
- json_type
------------
+SELECT json_get_type(to_json(FALSE));
+ json_get_type
+---------------
bool
(1 row)
-SELECT json_type(to_json(1=1));
- json_type
------------
+SELECT json_get_type(to_json(1=1));
+ json_get_type
+---------------
bool
(1 row)
-SELECT json_type(to_json(1=2));
- json_type
------------
+SELECT json_get_type(to_json(1=2));
+ json_get_type
+---------------
bool
(1 row)
diff --git a/json.sgml b/json.sgml
index ad48a2f..f876d58 100644
--- a/json.sgml
+++ b/json.sgml
@@ -141,8 +141,8 @@
<entry><literal>'"&#9835;"' -- if encoding supports Unicode</literal></entry>
</row>
<row>
- <entry><function>json_type(json)</function></entry>
- <entry><type>json_type_t</type>&nbsp;-&nbsp;&nbsp;one&nbsp;of:
+ <entry><function>json_get_type(json)</function></entry>
+ <entry><type>json_type</type>&nbsp;-&nbsp;&nbsp;one&nbsp;of:
<programlisting>
'null'
'string'
@@ -153,7 +153,7 @@
</programlisting>
</entry>
<entry>Get the type of a <type>json</type> value.</entry>
- <entry><literal>json_type('{"pi": "3.14159", "e": "2.71828"}')</literal></entry>
+ <entry><literal>json_get_type('{"pi": "3.14159", "e": "2.71828"}')</literal></entry>
<entry><literal>'object'</literal></entry>
</row>
</tbody>
diff --git a/json.sql.in b/json.sql.in
index 7176e4b..7db0790 100644
--- a/json.sql.in
+++ b/json.sql.in
@@ -13,21 +13,9 @@ RETURNS cstring
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
-CREATE OR REPLACE FUNCTION json_recv(internal)
-RETURNS json
-AS 'MODULE_PATHNAME'
-LANGUAGE C STRICT IMMUTABLE;
-
-CREATE OR REPLACE FUNCTION json_send(json)
-RETURNS bytea
-AS 'MODULE_PATHNAME'
-LANGUAGE C STRICT IMMUTABLE;
-
CREATE TYPE json (
INPUT = json_in,
OUTPUT = json_out,
- RECEIVE = json_recv,
- SEND = json_send,
INTERNALLENGTH = VARIABLE,
STORAGE = extended,
@@ -37,11 +25,11 @@ CREATE TYPE json (
);
-- Keep the labels of this enum in sync with enum_type_names[] in json_ops.c .
-CREATE TYPE json_type_t AS ENUM ('null', 'string', 'number', 'bool', 'object', 'array');
+CREATE TYPE json_type AS ENUM ('null', 'string', 'number', 'bool', 'object', 'array');
-CREATE OR REPLACE FUNCTION json_type(json)
-RETURNS json_type_t
-AS 'MODULE_PATHNAME','json_get_type'
+CREATE OR REPLACE FUNCTION json_get_type(json)
+RETURNS json_type
+AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION json_validate(text)
diff --git a/json_io.c b/json_io.c
index 315191f..a9f8604 100644
--- a/json_io.c
+++ b/json_io.c
@@ -65,52 +65,6 @@ json_out(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(string);
}
-PG_FUNCTION_INFO_V1(json_recv);
-Datum json_recv(PG_FUNCTION_ARGS);
-Datum
-json_recv(PG_FUNCTION_ARGS)
-{
- StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
- char *str;
- int nbytes;
- jsontype *result;
-
- str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
-
- if (!json_validate_server_encoded(str))
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
- errmsg("could not parse JSON value")));
-
- result = cstring_to_text_with_len(str, nbytes);
- pfree(str);
-
- PG_RETURN_JSON_P(result);
-}
-
-PG_FUNCTION_INFO_V1(json_send);
-Datum json_send(PG_FUNCTION_ARGS);
-Datum
-json_send(PG_FUNCTION_ARGS)
-{
- jsontype *t = PG_GETARG_JSON_P(0);
- StringInfoData buf;
-
-#ifdef USE_ASSERT_CHECKING
- {
- char *string = text_to_cstring(t);
-
- Assert(json_validate_server_encoded(string));
-
- pfree(string);
- }
-#endif
-
- pq_begintypsend(&buf);
- pq_sendtext(&buf, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t));
- PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
-}
-
/*
* Performs JSON value extraction in UTF-8 C-String land.
*
diff --git a/json_op.c b/json_op.c
index 77ab242..308ec09 100644
--- a/json_op.c
+++ b/json_op.c
@@ -66,7 +66,7 @@ json_get_type(PG_FUNCTION_ARGS)
label_oids = fcinfo->flinfo->fn_extra =
MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
JSON_TYPE_COUNT * sizeof(Oid));
- getEnumLabelOids("json_type_t", enum_labels, label_oids, JSON_TYPE_COUNT);
+ getEnumLabelOids("json_type", enum_labels, label_oids, JSON_TYPE_COUNT);
}
PG_RETURN_OID(label_oids[type]);
diff --git a/sql/json.sql b/sql/json.sql
index 526c881..8bf5457 100644
--- a/sql/json.sql
+++ b/sql/json.sql
@@ -16,11 +16,11 @@ SELECT '{"key1":"value1", "key2":"value2"}'::JSON;
SELECT '{"key1":"value1", "key2":"value2"}'::JSON;
SELECT 15::JSON;
-SELECT json_type('[]');
-SELECT json_type('{}');
-SELECT json_type('true');
-SELECT json_type('false');
-SELECT json_type('null');
+SELECT json_get_type('[]');
+SELECT json_get_type('{}');
+SELECT json_get_type('true');
+SELECT json_get_type('false');
+SELECT json_get_type('null');
CREATE TABLE testjson (j JSON);
INSERT INTO testjson VALUES ('[1,2,3,4]');
@@ -36,7 +36,7 @@ INSERT INTO testjson VALUES ('{}');
SELECT * FROM testjson;
-SELECT json_type(j) FROM testjson;
+SELECT json_get_type(j) FROM testjson;
-- to_json: null
@@ -46,44 +46,44 @@ SELECT to_json(NULL::INT[]);
SELECT to_json(NULL::VOID);
SELECT to_json(NULL::MONEY);
SELECT to_json('null'::text); -- should yield '"null"', not 'null'
-SELECT json_type(to_json(NULL));
-SELECT json_type(to_json(NULL::INT));
-SELECT json_type(to_json(NULL::VOID));
-SELECT json_type(to_json(NULL::MONEY));
+SELECT json_get_type(to_json(NULL));
+SELECT json_get_type(to_json(NULL::INT));
+SELECT json_get_type(to_json(NULL::VOID));
+SELECT json_get_type(to_json(NULL::MONEY));
-- to_json: string
SELECT to_json('');
-SELECT json_type(to_json(''));
+SELECT json_get_type(to_json(''));
SELECT to_json('string');
-SELECT json_type(to_json('string'));
+SELECT json_get_type(to_json('string'));
SELECT to_json('string'::VARCHAR);
-SELECT json_type(to_json('string'::VARCHAR));
+SELECT json_get_type(to_json('string'::VARCHAR));
SELECT to_json('string'::VARCHAR(3));
-SELECT json_type(to_json('string'::VARCHAR(3)));
+SELECT json_get_type(to_json('string'::VARCHAR(3)));
SELECT to_json('{1,2,3}'::TEXT);
-SELECT json_type(to_json('{1,2,3}'::TEXT));
+SELECT json_get_type(to_json('{1,2,3}'::TEXT));
SELECT to_json('"doubly-encoded"'::JSON);
-SELECT json_type(to_json('"doubly-encoded"'::JSON));
+SELECT json_get_type(to_json('"doubly-encoded"'::JSON));
SELECT to_json('"nested quotes"'::TEXT);
-SELECT json_type(to_json('"nested quotes"'::TEXT));
+SELECT json_get_type(to_json('"nested quotes"'::TEXT));
SELECT to_json('"nested quotes"'::TEXT)::TEXT::JSON;
-SELECT json_type(to_json('"nested quotes"'::TEXT)::TEXT::JSON);
+SELECT json_get_type(to_json('"nested quotes"'::TEXT)::TEXT::JSON);
SELECT to_json('h'::CHAR);
-SELECT json_type(to_json('h'::CHAR));
+SELECT json_get_type(to_json('h'::CHAR));
SELECT to_json('hello world'::CHAR);
-SELECT json_type(to_json('hello world'::CHAR));
+SELECT json_get_type(to_json('hello world'::CHAR));
SELECT to_json('hello world!'::CHAR(11));
-SELECT json_type(to_json('hello world!'::CHAR(11)));
+SELECT json_get_type(to_json('hello world!'::CHAR(11)));
-- to_json: number
SELECT to_json(12345);
SELECT to_json(12345.678);
-SELECT json_type(to_json(12345));
-SELECT json_type(to_json(12345.678));
+SELECT json_get_type(to_json(12345));
+SELECT json_get_type(to_json(12345.678));
SELECT to_json(+1.23e100::FLOAT);
SELECT to_json('+1.23e100'::FLOAT);
SELECT to_json(123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890123456789012345678901234567890);
-SELECT json_type(to_json(123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890123456789012345678901234567890));
+SELECT json_get_type(to_json(123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890123456789012345678901234567890));
SELECT to_json('100'::MONEY);
-- to_json: bool
@@ -91,10 +91,10 @@ SELECT to_json(TRUE);
SELECT to_json(FALSE);
SELECT to_json(1=1);
SELECT to_json(1=2);
-SELECT json_type(to_json(TRUE));
-SELECT json_type(to_json(FALSE));
-SELECT json_type(to_json(1=1));
-SELECT json_type(to_json(1=2));
+SELECT json_get_type(to_json(TRUE));
+SELECT json_get_type(to_json(FALSE));
+SELECT json_get_type(to_json(1=1));
+SELECT json_get_type(to_json(1=2));
SELECT to_json(TRUE::TEXT)::TEXT = '"' || TRUE || '"';
SELECT to_json(FALSE::TEXT)::TEXT = '"' || FALSE || '"';
diff --git a/uninstall_json.sql b/uninstall_json.sql
index 52abb1b..7bd0fc1 100644
--- a/uninstall_json.sql
+++ b/uninstall_json.sql
@@ -2,7 +2,7 @@
SET search_path = public;
DROP TYPE json CASCADE;
-DROP TYPE json_type_t;
+DROP TYPE json_type;
DROP FUNCTION json_validate(text);
DROP FUNCTION parse_json_path(text);