1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-26 09:41:40 +03:00

Add test coverage for indirection transformation

These tests cover nested arrays of composite data types,
single-argument functions, and casting using dot-notation, providing a
baseline for future enhancements to jsonb dot-notation support.

Author: Alexandra Wang <alexandra.wang.oss@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAK98qZ1JNNAx4QneJG+eX7iLesOhd6A68FNQVvvHP6Up_THf3A@mail.gmail.com
This commit is contained in:
Peter Eisentraut
2026-01-06 09:37:19 +01:00
parent bf308639bf
commit 6449291728
4 changed files with 132 additions and 7 deletions

View File

@@ -1782,17 +1782,17 @@ SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
(1 row)
-- A few simple tests for arrays of composite types
create type comptype as (f1 int, f2 text);
create type comptype as (f1 int, f2 text, f3 int[]);
create table comptable (c1 comptype, c2 comptype[]);
-- XXX would like to not have to specify row() construct types here ...
insert into comptable
values (row(1,'foo'), array[row(2,'bar')::comptype, row(3,'baz')::comptype]);
values (row(1,'foo',array[10,20]), array[row(2,'bar',array[30,40])::comptype, row(3,'baz',array[50,60])::comptype]);
-- check that implicitly named array type _comptype isn't a problem
create type _comptype as enum('fooey');
select * from comptable;
c1 | c2
---------+-----------------------
(1,foo) | {"(2,bar)","(3,baz)"}
c1 | c2
-------------------+-----------------------------------------------
(1,foo,"{10,20}") | {"(2,bar,\"{30,40}\")","(3,baz,\"{50,60}\")"}
(1 row)
select c2[2].f2 from comptable;
@@ -1801,6 +1801,22 @@ select c2[2].f2 from comptable;
baz
(1 row)
select c2[2].f3 from comptable;
f3
---------
{50,60}
(1 row)
select c2[2].f3[1:2] from comptable;
f3
---------
{50,60}
(1 row)
select c2[1:2].f3[1:2] from comptable;
ERROR: column notation .f3 applied to type comptype[], which is not a composite type
LINE 1: select c2[1:2].f3[1:2] from comptable;
^
drop type _comptype;
drop table comptable;
drop type comptype;

View File

@@ -5863,3 +5863,91 @@ select '12345.0000000000000000000000000000000000000000000005'::jsonb::int8;
12345
(1 row)
-- single argument jsonb functions as jsonb_function(jsonb) and jsonb.jsonb_function
select jsonb_typeof('{"a":1}'::jsonb);
jsonb_typeof
--------------
object
(1 row)
select ('{"a":1}'::jsonb).jsonb_typeof;
jsonb_typeof
--------------
object
(1 row)
select jsonb_array_length('["a", "b", "c"]'::jsonb);
jsonb_array_length
--------------------
3
(1 row)
select ('["a", "b", "c"]'::jsonb).jsonb_array_length;
jsonb_array_length
--------------------
3
(1 row)
select jsonb_object_keys('{"a":1, "b":2}'::jsonb);
jsonb_object_keys
-------------------
a
b
(2 rows)
select ('{"a":1, "b":2}'::jsonb).jsonb_object_keys;
jsonb_object_keys
-------------------
a
b
(2 rows)
-- cast jsonb to other types as (jsonb)::type and (jsonb).type
select ('123.45'::jsonb)::numeric;
numeric
---------
123.45
(1 row)
select ('123.45'::jsonb).numeric;
numeric
---------
123.45
(1 row)
select ('[{"name": "alice"}, {"name": "bob"}]'::jsonb)::name;
name
--------------------------------------
[{"name": "alice"}, {"name": "bob"}]
(1 row)
select ('[{"name": "alice"}, {"name": "bob"}]'::jsonb).name;
name
--------------------------------------
[{"name": "alice"}, {"name": "bob"}]
(1 row)
select ('true'::jsonb)::bool;
bool
------
t
(1 row)
select ('true'::jsonb).bool;
bool
------
t
(1 row)
select ('{"text": "hello"}'::jsonb)::text;
text
-------------------
{"text": "hello"}
(1 row)
select ('{"text": "hello"}'::jsonb).text;
text
-------------------
{"text": "hello"}
(1 row)

View File

@@ -555,19 +555,22 @@ SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
-- A few simple tests for arrays of composite types
create type comptype as (f1 int, f2 text);
create type comptype as (f1 int, f2 text, f3 int[]);
create table comptable (c1 comptype, c2 comptype[]);
-- XXX would like to not have to specify row() construct types here ...
insert into comptable
values (row(1,'foo'), array[row(2,'bar')::comptype, row(3,'baz')::comptype]);
values (row(1,'foo',array[10,20]), array[row(2,'bar',array[30,40])::comptype, row(3,'baz',array[50,60])::comptype]);
-- check that implicitly named array type _comptype isn't a problem
create type _comptype as enum('fooey');
select * from comptable;
select c2[2].f2 from comptable;
select c2[2].f3 from comptable;
select c2[2].f3[1:2] from comptable;
select c2[1:2].f3[1:2] from comptable;
drop type _comptype;
drop table comptable;

View File

@@ -1596,3 +1596,21 @@ select '12345.0000000000000000000000000000000000000000000005'::jsonb::float8;
select '12345.0000000000000000000000000000000000000000000005'::jsonb::int2;
select '12345.0000000000000000000000000000000000000000000005'::jsonb::int4;
select '12345.0000000000000000000000000000000000000000000005'::jsonb::int8;
-- single argument jsonb functions as jsonb_function(jsonb) and jsonb.jsonb_function
select jsonb_typeof('{"a":1}'::jsonb);
select ('{"a":1}'::jsonb).jsonb_typeof;
select jsonb_array_length('["a", "b", "c"]'::jsonb);
select ('["a", "b", "c"]'::jsonb).jsonb_array_length;
select jsonb_object_keys('{"a":1, "b":2}'::jsonb);
select ('{"a":1, "b":2}'::jsonb).jsonb_object_keys;
-- cast jsonb to other types as (jsonb)::type and (jsonb).type
select ('123.45'::jsonb)::numeric;
select ('123.45'::jsonb).numeric;
select ('[{"name": "alice"}, {"name": "bob"}]'::jsonb)::name;
select ('[{"name": "alice"}, {"name": "bob"}]'::jsonb).name;
select ('true'::jsonb)::bool;
select ('true'::jsonb).bool;
select ('{"text": "hello"}'::jsonb)::text;
select ('{"text": "hello"}'::jsonb).text;