Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test works

  • Loading branch information...
commit 42f8af49bfc0c82c87d70db2c28bbb148581c022 1 parent 1d4f3e2
theirix authored
2  Makefile
View
@@ -5,7 +5,7 @@ EXTENSION = json_accessors_c
DATA = json_accessors_c--1.2.sql
PG_CPPFLAGS =
-REGRESS = postgre-json-functions
+REGRESS = json_accessors_c
PG_CONFIG := pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
85 expected/json_accessors_c.out
View
@@ -0,0 +1,85 @@
+set client_min_messages to 'error';
+drop extension if exists "json_accessors_c" cascade;
+create extension "json_accessors_c";
+set client_min_messages to 'notice';
+\t on
+\pset format unaligned
+-- qq
+select json_get_text('{"foo":"qq", "bar": true}', 'foo');
+qq
+-- t
+select json_get_boolean('{"foo":"qq", "bar": true}', 'bar');
+t
+-- 42
+select json_get_int('{"baz": 42, "boo": 42.424242}', 'baz');
+42
+-- 42
+select json_get_bigint('{"baz": 42, "boo": 42.424242}', 'baz');
+42
+-- 9223372036854
+select json_get_bigint('{"baz": 9223372036854, "boo": 42.424242}', 'baz');
+9223372036854
+-- 42.424242
+select json_get_numeric('{"baz": 42, "boo": 42.424242}', 'boo');
+42.424242
+-- Tue Dec 01 01:23:45 2009
+select json_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar');
+Tue Dec 01 01:23:45 2009
+set time zone EST;
+-- 2009-12-01 01:23:45
+select to_char(json_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar'), 'YYYY-MM-DD HH:MI:SSTZ');
+2009-12-01 01:23:45
+set time zone "Europe/Moscow";
+-- 2009-12-01 01:23:45
+select to_char(json_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar'), 'YYYY-MM-DD HH:MI:SSTZ');
+2009-12-01 01:23:45
+-- {foo,bar}
+select json_array_to_text_array('["foo", "bar"]');
+{foo,bar}
+-- {t,f}
+select json_array_to_boolean_array('[true, false]');
+{t,f}
+-- {42,43}
+select json_array_to_int_array('[42, 43]');
+{42,43}
+-- {42,9223372036854}
+select json_array_to_bigint_array('[42, 9223372036854]');
+{42,9223372036854}
+-- {42.4242,43.4343}
+select json_array_to_numeric_array('[42.4242,43.4343]');
+{42.4242,43.4343}
+-- {"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
+select json_array_to_timestamp_array('["2009-12-01 01:23:45", "2012-12-01 01:23:45"]');
+{"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
+-- {baz1,baz2,baz3}
+select json_get_text_array('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar');
+{baz1,baz2,baz3}
+-- {t,f}
+select json_get_boolean_array('{"foo":"qq", "bar": [true, false]}', 'bar');
+{t,f}
+-- {42,43}
+select json_get_int_array('{"foo":"qq", "bar": [42, 43]}', 'bar');
+{42,43}
+-- {42,9223372036854}
+select json_get_bigint_array('{"foo":"qq", "bar": [42, 9223372036854]}', 'bar');
+{42,9223372036854}
+-- {42.4242,43.4343}
+select json_get_numeric_array('{"foo":"qq", "bar": [42.4242,43.4343]}', 'bar');
+{42.4242,43.4343}
+-- {"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
+select json_get_timestamp_array('{"foo":"qq", "bar": ["2009-12-01 01:23:45", "2012-12-01 01:23:45"]}', 'bar');
+{"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
+-- "qq"
+select json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'foo');
+"qq"
+-- ["baz1","baz2","baz3"]
+select json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar');
+["baz1","baz2","baz3"]
+-- {baz1,baz2,baz3}
+select json_array_to_text_array(json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar'));
+{baz1,baz2,baz3}
+-- baz2
+select (json_array_to_text_array(json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar')))[2];
+baz2
+\t off
+\pset format aligned
85 expected/postgre-json-functions.out
View
@@ -1,85 +0,0 @@
-set client_min_messages to 'error';
-drop extension if exists "postgre-json-functions" cascade;
-create extension "postgre-json-functions";
-set client_min_messages to 'notice';
-\t on
-\pset format unaligned
--- qq
-select json_object_get_text('{"foo":"qq", "bar": true}', 'foo');
-qq
--- t
-select json_object_get_boolean('{"foo":"qq", "bar": true}', 'bar');
-t
--- 42
-select json_object_get_int('{"baz": 42, "boo": 42.424242}', 'baz');
-42
--- 42
-select json_object_get_bigint('{"baz": 42, "boo": 42.424242}', 'baz');
-42
--- 9223372036854
-select json_object_get_bigint('{"baz": 9223372036854, "boo": 42.424242}', 'baz');
-9223372036854
--- 42.424242
-select json_object_get_numeric('{"baz": 42, "boo": 42.424242}', 'boo');
-42.424242
--- Tue Dec 01 01:23:45 2009
-select json_object_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar');
-Tue Dec 01 01:23:45 2009
-set time zone EST;
--- 2009-12-01 01:23:45
-select to_char(json_object_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar'), 'YYYY-MM-DD HH:MI:SSTZ');
-2009-12-01 01:23:45
-set time zone "Europe/Moscow";
--- 2009-12-01 01:23:45
-select to_char(json_object_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar'), 'YYYY-MM-DD HH:MI:SSTZ');
-2009-12-01 01:23:45
--- {foo,bar}
-select json_array_to_text_array('["foo", "bar"]');
-{foo,bar}
--- {t,f}
-select json_array_to_boolean_array('[true, false]');
-{t,f}
--- {42,43}
-select json_array_to_int_array('[42, 43]');
-{42,43}
--- {42,9223372036854}
-select json_array_to_bigint_array('[42, 9223372036854]');
-{42,9223372036854}
--- {42.4242,43.4343}
-select json_array_to_numeric_array('[42.4242,43.4343]');
-{42.4242,43.4343}
--- {"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
-select json_array_to_timestamp_array('["2009-12-01 01:23:45", "2012-12-01 01:23:45"]');
-{"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
--- {baz1,baz2,baz3}
-select json_object_get_text_array('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar');
-{baz1,baz2,baz3}
--- {t,f}
-select json_object_get_boolean_array('{"foo":"qq", "bar": [true, false]}', 'bar');
-{t,f}
--- {42,43}
-select json_object_get_int_array('{"foo":"qq", "bar": [42, 43]}', 'bar');
-{42,43}
--- {42,9223372036854}
-select json_object_get_bigint_array('{"foo":"qq", "bar": [42, 9223372036854]}', 'bar');
-{42,9223372036854}
--- {42.4242,43.4343}
-select json_object_get_numeric_array('{"foo":"qq", "bar": [42.4242,43.4343]}', 'bar');
-{42.4242,43.4343}
--- {"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
-select json_object_get_timestamp_array('{"foo":"qq", "bar": ["2009-12-01 01:23:45", "2012-12-01 01:23:45"]}', 'bar');
-{"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
--- "qq"
-select json_object_to_string('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'foo');
-"qq"
--- ["baz1","baz2","baz3"]
-select json_object_to_string('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar');
-["baz1","baz2","baz3"]
--- {baz1,baz2,baz3}
-select json_array_to_text_array(json_object_to_string('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar'));
-{baz1,baz2,baz3}
--- baz2
-select (json_array_to_text_array(json_object_to_string('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar')))[2];
-baz2
-\t off
-\pset format aligned
114 expected/postgre-json-gin.out
View
@@ -1,114 +0,0 @@
-set client_min_messages to 'error';
-drop extension if exists "postgre-json-functions" cascade;
-create extension "postgre-json-functions";
-set client_min_messages to 'notice';
-\t on
-\pset format unaligned
--- t
-select array['foo', 'bar', 'baz'] @> array['foo'];
-t
--- t
-select array['foo', 'bar', 'baz'] @> array['foo', 'bar'];
-t
--- t
-select array['foo', 'bar', 'baz'] @> array['baz', 'foo'];
-t
--- f
-select array['foo', 'bar', 'baz'] @> array['qux'];
-f
--- t
-select array['foo', 'bar', 'baz'] @> array[]::text[];
-t
--- t
-select array[]::text[] @> array[]::text[];
-t
--- f
-select array[]::text[] @> array['qux'];
-f
--- t
-select array['foo', 'bar', 'baz'] @@> array['foo'];
-t
--- t
-select array['foo', 'bar', 'baz'] @@> array['foo', 'bar'];
-t
--- t
-select array['foo', 'bar', 'baz'] @@> array['baz', 'foo'];
-t
--- f
-select array['foo', 'bar', 'baz'] @@> array['qux'];
-f
--- t
-select array['foo', 'bar', 'baz'] @@> array[]::text[];
-t
--- t
-select array[]::text[] @> array[]::text[];
-t
--- f
-select array[]::text[] @> array['qux'];
-f
--- t
-select array['foo', 'bar', 'baz'] @@> array['fo'];
-t
--- t
-select array['foo', 'bar', 'baz'] @@> array['ba'];
-t
--- t
-select array['foo', 'bar', 'baz'] @@> array['b'];
-t
--- t
-select array['foo', 'bar', 'baz'] @@> array[''];
-t
--- f
-select array['foo', 'bar', 'baz'] @@> array['baq'];
-f
--- t
-select array['foo', 'foobar', 'baz'] @@> array['foo'];
-t
-set client_min_messages to 'error';
-drop table if exists test_table;
-create table test_table(id bigserial, val text);
-set client_min_messages to 'notice';
-insert into test_table(val) values('{"create_date":"2009-12-01 01:23:45","tags":["foo1","bar1","baz1"]}');
-insert into test_table(val) values('{"create_date":"2009-12-02 01:23:45","tags":["foo2","bar2","baz2"]}');
-insert into test_table(val) values('{"create_date":"2009-12-03 01:23:45","tags":["foo3","bar3","baz3"]}');
-insert into test_table(val) select val from test_table;
-insert into test_table(val) select val from test_table;
-insert into test_table(val) select val from test_table;
-insert into test_table(val) values('{"create_date":"2009-12-04 01:23:45","tags":["foo4","bar4","baz4"]}');
-insert into test_table(val) values('{"create_date":"2009-12-04 01:23:45","tags":["foo4","bar4","baz4"]}');
-insert into test_table(val) values('{"create_date":"2009-12-04 01:23:45","tags":["foo4","bar4","baz4"]}');
-insert into test_table(val) values('{"create_date":"2009-12-04 01:23:45","tags":["foo4","bar4one","baz4"]}');
-insert into test_table(val) values('{"create_date":"2009-12-04 01:23:45","tags":["foo4","bar4two","baz4"]}');
-insert into test_table(val) values('{"create_date":"2009-12-04 01:23:45","tags":["foo4","bar4three","baz4"]}');
--- 30
-select count(*) from test_table;
-30
--- NOTICE: index "test_tags_idx" does not exist, skipping
-drop index if exists test_tags_idx;
-NOTICE: index "test_tags_idx" does not exist, skipping
-create index test_tags_idx on test_table using gin (json_object_get_text_array(val, 'tags') json_gin_ops);
--- 6
-select count(*) from test_table where json_object_get_text_array(val, 'tags') @@> array['bar4'];
-6
--- 3
-select count(*) from test_table where json_object_get_text_array(val, 'tags') @> array['bar4'];
-3
--- 8
-select count(*) from test_table where json_object_get_text_array(val, 'tags') @@> array['bar3'];
-8
--- 8
-select count(*) from test_table where json_object_get_text_array(val, 'tags') @> array['bar3'];
-8
--- 0
-select count(*) from test_table where json_object_get_text_array(val, 'tags') @@> array['qux'];
-0
--- 0
-select count(*) from test_table where json_object_get_text_array(val, 'tags') @> array['qux'];
-0
------ select count(*) from test_table where json_object_get_text_array(val, 'tags') @@> array[]::text[];
------ select count(*) from test_table where json_object_get_text_array(val, 'tags') @> array[]::text[];
--- 30
-select count(*) from test_table where json_object_get_text_array(val, 'tags') @@> array[''];
-30
-\t off
-\pset format aligned
67 sql/json_accessors_c.sql
View
@@ -0,0 +1,67 @@
+set client_min_messages to 'error';
+drop extension if exists "json_accessors_c" cascade;
+create extension "json_accessors_c";
+set client_min_messages to 'notice';
+
+\t on
+\pset format unaligned
+
+-- qq
+select json_get_text('{"foo":"qq", "bar": true}', 'foo');
+-- t
+select json_get_boolean('{"foo":"qq", "bar": true}', 'bar');
+-- 42
+select json_get_int('{"baz": 42, "boo": 42.424242}', 'baz');
+-- 42
+select json_get_bigint('{"baz": 42, "boo": 42.424242}', 'baz');
+-- 9223372036854
+select json_get_bigint('{"baz": 9223372036854, "boo": 42.424242}', 'baz');
+-- 42.424242
+select json_get_numeric('{"baz": 42, "boo": 42.424242}', 'boo');
+
+-- Tue Dec 01 01:23:45 2009
+select json_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar');
+set time zone EST;
+-- 2009-12-01 01:23:45
+select to_char(json_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar'), 'YYYY-MM-DD HH:MI:SSTZ');
+set time zone "Europe/Moscow";
+-- 2009-12-01 01:23:45
+select to_char(json_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar'), 'YYYY-MM-DD HH:MI:SSTZ');
+
+-- {foo,bar}
+select json_array_to_text_array('["foo", "bar"]');
+-- {t,f}
+select json_array_to_boolean_array('[true, false]');
+-- {42,43}
+select json_array_to_int_array('[42, 43]');
+-- {42,9223372036854}
+select json_array_to_bigint_array('[42, 9223372036854]');
+-- {42.4242,43.4343}
+select json_array_to_numeric_array('[42.4242,43.4343]');
+-- {"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
+select json_array_to_timestamp_array('["2009-12-01 01:23:45", "2012-12-01 01:23:45"]');
+
+-- {baz1,baz2,baz3}
+select json_get_text_array('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar');
+-- {t,f}
+select json_get_boolean_array('{"foo":"qq", "bar": [true, false]}', 'bar');
+-- {42,43}
+select json_get_int_array('{"foo":"qq", "bar": [42, 43]}', 'bar');
+-- {42,9223372036854}
+select json_get_bigint_array('{"foo":"qq", "bar": [42, 9223372036854]}', 'bar');
+-- {42.4242,43.4343}
+select json_get_numeric_array('{"foo":"qq", "bar": [42.4242,43.4343]}', 'bar');
+-- {"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
+select json_get_timestamp_array('{"foo":"qq", "bar": ["2009-12-01 01:23:45", "2012-12-01 01:23:45"]}', 'bar');
+
+-- "qq"
+select json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'foo');
+-- ["baz1","baz2","baz3"]
+select json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar');
+-- {baz1,baz2,baz3}
+select json_array_to_text_array(json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar'));
+-- baz2
+select (json_array_to_text_array(json_get_object('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar')))[2];
+
+\t off
+\pset format aligned
67 sql/postgre-json-functions.sql
View
@@ -1,67 +0,0 @@
-set client_min_messages to 'error';
-drop extension if exists "postgre-json-functions" cascade;
-create extension "postgre-json-functions";
-set client_min_messages to 'notice';
-
-\t on
-\pset format unaligned
-
--- qq
-select json_object_get_text('{"foo":"qq", "bar": true}', 'foo');
--- t
-select json_object_get_boolean('{"foo":"qq", "bar": true}', 'bar');
--- 42
-select json_object_get_int('{"baz": 42, "boo": 42.424242}', 'baz');
--- 42
-select json_object_get_bigint('{"baz": 42, "boo": 42.424242}', 'baz');
--- 9223372036854
-select json_object_get_bigint('{"baz": 9223372036854, "boo": 42.424242}', 'baz');
--- 42.424242
-select json_object_get_numeric('{"baz": 42, "boo": 42.424242}', 'boo');
-
--- Tue Dec 01 01:23:45 2009
-select json_object_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar');
-set time zone EST;
--- 2009-12-01 01:23:45
-select to_char(json_object_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar'), 'YYYY-MM-DD HH:MI:SSTZ');
-set time zone "Europe/Moscow";
--- 2009-12-01 01:23:45
-select to_char(json_object_get_timestamp('{"foo":"qq", "bar": "2009-12-01 01:23:45"}', 'bar'), 'YYYY-MM-DD HH:MI:SSTZ');
-
--- {foo,bar}
-select json_array_to_text_array('["foo", "bar"]');
--- {t,f}
-select json_array_to_boolean_array('[true, false]');
--- {42,43}
-select json_array_to_int_array('[42, 43]');
--- {42,9223372036854}
-select json_array_to_bigint_array('[42, 9223372036854]');
--- {42.4242,43.4343}
-select json_array_to_numeric_array('[42.4242,43.4343]');
--- {"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
-select json_array_to_timestamp_array('["2009-12-01 01:23:45", "2012-12-01 01:23:45"]');
-
--- {baz1,baz2,baz3}
-select json_object_get_text_array('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar');
--- {t,f}
-select json_object_get_boolean_array('{"foo":"qq", "bar": [true, false]}', 'bar');
--- {42,43}
-select json_object_get_int_array('{"foo":"qq", "bar": [42, 43]}', 'bar');
--- {42,9223372036854}
-select json_object_get_bigint_array('{"foo":"qq", "bar": [42, 9223372036854]}', 'bar');
--- {42.4242,43.4343}
-select json_object_get_numeric_array('{"foo":"qq", "bar": [42.4242,43.4343]}', 'bar');
--- {"Tue Dec 01 01:23:45 2009","Sat Dec 01 01:23:45 2012"}
-select json_object_get_timestamp_array('{"foo":"qq", "bar": ["2009-12-01 01:23:45", "2012-12-01 01:23:45"]}', 'bar');
-
--- "qq"
-select json_object_to_string('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'foo');
--- ["baz1","baz2","baz3"]
-select json_object_to_string('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar');
--- {baz1,baz2,baz3}
-select json_array_to_text_array(json_object_to_string('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar'));
--- baz2
-select (json_array_to_text_array(json_object_to_string('{"foo":"qq", "bar": ["baz1", "baz2", "baz3"]}', 'bar')))[2];
-
-\t off
-\pset format aligned
Please sign in to comment.
Something went wrong with that request. Please try again.