PostgreSQL 17.12Lab-verified · 2026-11-29

PostgreSQL 22023: cannot cast jsonb string to type numeric

A value handed to a cast or setting is the wrong kind: a jsonb string/object cast to a number, or an unknown time zone name.

PostgreSQL 17.12
22023: cannot cast jsonb string to type numeric

Jump to a cause

  1. 01Casting a jsonb string from -> to numeric
  2. 02Casting a nested jsonb object to integer
  3. 03Time zone abbreviation such as KST in SET TIME ZONE

Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-29 · container image postgres:17

SQLSTATE 22023 (invalid_parameter_value) is a general code. In everyday SQL it shows up most often when you cast a jsonb value with -> straight to a number, and when SET or a connection option gets a value the server does not accept, such as a time zone name.

The three runs below cover those cases. For jsonb, jsonb_typeof() tells you what kind of value you actually have.

01Casting a jsonb string from -> to numeric

The JSON stored the price as a string ("1000"). (data->'price')::numeric failed with cannot cast jsonb string to type numeric, because -> returns jsonb and a jsonb string cannot be cast to a number.

jsonb_typeof showed string, and ->> returned the plain text 1000. SUM((data->>'price')::numeric) worked and returned 3500.

Setup
Setuprun as lab_a
CREATE TABLE orders (id int PRIMARY KEY, data jsonb);
INSERT INTO orders VALUES (1, '{"price": "1000", "item": {"code": "A1", "qty": 2}}'), (2, '{"price": "2500", "item": {"code": "B7", "qty": 1}}');
OUTPUT
CREATE TABLE
INSERT 0 2
Reproducerun as lab_a
SELECT SUM((data->'price')::numeric) AS total FROM orders;
✕ ERROR
ERROR:  22023: cannot cast jsonb string to type numeric
Checkrun as lab_a
SELECT id, data->'price' AS arrow, jsonb_typeof(data->'price') AS type, data->>'price' AS text_value FROM orders ORDER BY id;
OUTPUT
 id | arrow  |  type  | text_value
----+--------+--------+------------
  1 | "1000" | string | 1000
  2 | "2500" | string | 2500
(2 rows)
After the fixrun as lab_a
SELECT SUM((data->>'price')::numeric) AS total FROM orders;
✓ SUCCESS
 total
-------
  3500
(1 row)

02Casting a nested jsonb object to integer

(data->'item')::int failed with cannot cast jsonb object to type integer. data->'item' is the whole object {"qty": 2, "code": "A1"}, not the number inside it.

jsonb_typeof showed object. Going one level deeper with (data->'item'->>'qty')::int, or using the path form (data #>> '{item,qty}')::int, returned 2 and 1.

Setup
Setuprun as lab_a
CREATE TABLE orders (id int PRIMARY KEY, data jsonb);
INSERT INTO orders VALUES (1, '{"price": "1000", "item": {"code": "A1", "qty": 2}}'), (2, '{"price": "2500", "item": {"code": "B7", "qty": 1}}');
OUTPUT
CREATE TABLE
INSERT 0 2
Reproducerun as lab_a
SELECT id, (data->'item')::int AS qty FROM orders;
✕ ERROR
ERROR:  22023: cannot cast jsonb object to type integer
Checkrun as lab_a
SELECT id, data->'item' AS item, jsonb_typeof(data->'item') AS type FROM orders ORDER BY id;
OUTPUT
 id |           item           |  type
----+--------------------------+--------
  1 | {"qty": 2, "code": "A1"} | object
  2 | {"qty": 1, "code": "B7"} | object
(2 rows)
After the fixrun as lab_a
SELECT id, (data->'item'->>'qty')::int AS qty, (data #>> '{item,qty}')::int AS qty2 FROM orders ORDER BY id;
✓ SUCCESS
 id | qty | qty2
----+-----+------
  1 |   2 |    2
  2 |   1 |    1
(2 rows)

03Time zone abbreviation such as KST in SET TIME ZONE

SET TIME ZONE 'KST' failed with invalid value for parameter "TimeZone": "KST". KST exists only as an abbreviation; the TimeZone setting expects a full zone name.

pg_timezone_names listed Asia/Seoul with abbrev KST and offset 09:00. SET TIME ZONE 'Asia/Seoul' worked, SHOW TimeZone returned Asia/Seoul, and 2024-01-05 00:00 UTC was shown as 09:00+09.

Reproducerun as lab_a
SET TIME ZONE 'KST';
✕ ERROR
ERROR:  22023: invalid value for parameter "TimeZone": "KST"
Checkrun as lab_a
SELECT name, abbrev, utc_offset FROM pg_timezone_names WHERE name IN ('Asia/Seoul', 'Asia/Tokyo') ORDER BY name;
OUTPUT
    name    | abbrev | utc_offset
------------+--------+------------
 Asia/Seoul | KST    | 09:00:00
 Asia/Tokyo | JST    | 09:00:00
(2 rows)
After the fixrun as lab_a
SET TIME ZONE 'Asia/Seoul';
SHOW TimeZone;
SELECT timestamptz '2024-01-05 00:00+00' AS seoul_time;
✓ SUCCESS
SET
  TimeZone
------------
 Asia/Seoul
(1 row)

       seoul_time
------------------------
 2024-01-05 09:00:00+09
(1 row)

FAQ

How do I convert a jsonb field to a number in PostgreSQL?

Take it out as text with ->> and cast that: (data->>'price')::numeric. For nested keys use data->'item'->>'qty' or data #>> '{item,qty}'.

Can a jsonb number be cast directly?

Our runs only cast jsonb strings and objects, which failed. Using ->> and then casting worked for those, and it is the safe choice when the stored type varies.

Why is 'KST' (or 'JST') rejected as a time zone?

The TimeZone parameter wants a zone name like Asia/Seoul or Asia/Tokyo. Look them up with SELECT name, abbrev FROM pg_timezone_names WHERE abbrev = 'KST';.

What does SQLSTATE 22023 mean?

invalid_parameter_value: an argument or setting value is not acceptable. The message text tells you which value; the cases above are the common ones.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12