Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cannot cast to jsonb if non-negative numeric vlaue have plus sign

the following command working

select '[0,1, -2,  -0.3444, 5.6]'::jsonb;

However the following 3 not working.

select '[0,1, -2,  (+0.3444), 5.6]'::jsonb;
select '[0,1, -2,  +0.3444, 5.6]'::jsonb;
select '[0,1, -2,  +0, 5.6]'::jsonb;

The following working.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

select +0.1;
select (+0.1)::text;

>Solution :

The first working example is a string containing a valid JSON document being cast as JSONB; the other ones contain valid PostgreSQL arithmetic expressions.

The non-working examples again have strings being cast into JSONB, but the strings contain invalid JSON expressions, and thus cannot be parsed as JSON. If you take a look at JSON grammar, number is integer fraction exponent, and integer can have digits that optionally start with -. The sign + is not allowed in JSON. The parentheses are not allowed, either. You can verify this e.g. using JSON validator.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading