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

[9.x] Use jsonb type for pgsql whereJsonLength #39619

Merged
merged 1 commit into from
Nov 15, 2021
Merged

[9.x] Use jsonb type for pgsql whereJsonLength #39619

merged 1 commit into from
Nov 15, 2021

Conversation

tpetry
Copy link
Contributor

@tpetry tpetry commented Nov 15, 2021

In PostgreSQL there are historically two different datatypes to store json data: The old json datatype storing everything as text and the new jsonb datatype with binary storage. The old textual storage is discouraged because it is in all respects inferior to binary storage, there are very few use cases where textual storage is advantageous.

Laravel uses the new jsonb datatype for all query builder operations, only whereJsonLength was forgotten to be adapted. Thus, any calculation of array length on jsonb columns first leads to a conversion of binary representation to textual representation. Since all other query builder operations work natively on jsonb, it is reasonable to adapt the only remaining function to fit the other query operations.

@tpetry tpetry changed the title use jsonb type for pgsql whereJsonLength [9.x] use jsonb type for pgsql whereJsonLength Nov 15, 2021
@taylorotwell
Copy link
Member

Does this work on both json and jsonb column types?

@tpetry
Copy link
Contributor Author

tpetry commented Nov 15, 2021

Yes it will work for both. In case a legacy json type is used it will be cast to jsonb.

@taylorotwell taylorotwell merged commit 5e0b273 into laravel:master Nov 15, 2021
@taylorotwell
Copy link
Member

I already merged this, but is there a big reason this couldn't just go into Laravel 8.x?

@tpetry tpetry deleted the postgresql-all-jsonb branch November 16, 2021 06:21
@tpetry
Copy link
Contributor Author

tpetry commented Nov 16, 2021

In a very very rare case this could be a breaking change. If someone built a functional index on the expression the index can‘t be used anymore because it‘s using a different function now.

@GrahamCampbell GrahamCampbell changed the title [9.x] use jsonb type for pgsql whereJsonLength [9.x] Use jsonb type for pgsql whereJsonLength Nov 16, 2021
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.

2 participants