Skip to content

Conversation

samuelcolvin
Copy link
Collaborator

WIP requires pydantic/jiter#128.

The idea is that since json_get_int and json_get_float now support parsing strings as well as floats and ints, although looking again at Postgres, I'm not sure this is correct.

Locally I see:

postgres@localhost:postgres> select ('{"foo": "123"}'::jsonb->>'foo')::numeric
╒═════════╕
│ numeric │
╞═════════╡
│ 123     │
╘═════════╛
SELECT 1
Time: 0.007s
postgres@localhost:postgres> select ('{"foo": "123"}'::jsonb->'foo')::numeric
cannot cast jsonb string to type numeric
Time: 0.002s

In other words ->> allows casting a string field to an int (since the operator returns a string, the same for {"foo": "123"} as {"foo": 123}), but -> returns JSON where casting from a string field to numeric is not supported.

@dmontagu @alexmojaki am I missing something?

@samuelcolvin
Copy link
Collaborator Author

I think this is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant