Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make json_get_int and json_get_float more lax #35

Closed
wants to merge 1 commit into from
Closed

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