1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-03 09:13:20 +03:00

Make jsonb casts to scalar types translate JSON null to SQL NULL.

Formerly, these cases threw an error "cannot cast jsonb null to type
<whatever>".  That seems less than helpful though.  It's also
inconsistent with the behavior of the ->> operator, which translates
JSON null to SQL NULL, as do some other jsonb functions.

Discussion: https://postgr.es/m/3851203.1722552717@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2025-01-24 13:20:44 -05:00
parent 13a255c195
commit a5579a90af
3 changed files with 149 additions and 7 deletions

View File

@@ -1540,12 +1540,25 @@ select ts_headline('[]'::jsonb, tsquery('aaa & bbb'));
-- casts
select 'true'::jsonb::bool;
select 'null'::jsonb::bool;
select '[]'::jsonb::bool;
select '1.0'::jsonb::float;
select 'null'::jsonb::float;
select '[1.0]'::jsonb::float;
select '1.0'::jsonb::float4;
select 'null'::jsonb::float4;
select '[1.0]'::jsonb::float4;
select '12345'::jsonb::int2;
select 'null'::jsonb::int2;
select '"hello"'::jsonb::int2;
select '12345'::jsonb::int4;
select 'null'::jsonb::int4;
select '"hello"'::jsonb::int4;
select '12345'::jsonb::int8;
select 'null'::jsonb::int8;
select '"hello"'::jsonb::int8;
select '12345'::jsonb::numeric;
select 'null'::jsonb::numeric;
select '{}'::jsonb::numeric;
select '12345.05'::jsonb::numeric;
select '12345.05'::jsonb::float4;