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

[5.6] Add JSON SELECT queries to SQL Server #24397

Merged
merged 1 commit into from
Jun 4, 2018
Merged

[5.6] Add JSON SELECT queries to SQL Server #24397

merged 1 commit into from
Jun 4, 2018

Conversation

staudenmeir
Copy link
Contributor

Adds JSON SELECT queries to SQL Server 2016+:

DB::table('users')->select('items->price')->where('items->price', 1)->orderBy('items->price');

I found two limitations:

  • In comparisons, Boolean values only work as strings: where('foo->bool', 'true')
    The downside is that this also selects "true" strings (PostgreSQL has the same problem).
  • Extracting arrays and objects doesn't work: select('foo->array') // returns null
    The reason is that SQL Server uses different functions for scalar values (JSON_VALUE()) and arrays/objects (JSON_QUERY()).
    MySQL and PostgreSQL return arrays and objects as JSON strings.

@sisve
Copy link
Contributor

sisve commented Jun 1, 2018

Can we detect the version of SQL Server used and throw an exception telling the user that the feature is unsupported for older SQL Server versions?

@staudenmeir
Copy link
Contributor Author

I'm not sure it's worth the effort. Users will get an error saying that the function doesn't exist.

As far as I see, we don't do database version checks anywhere else.

@sisve
Copy link
Contributor

sisve commented Jun 1, 2018 via email

@staudenmeir
Copy link
Contributor Author

staudenmeir commented Jun 1, 2018

You're right about the error message.

I like the idea of version-specific grammars. I think it's a better approach than checking the database version when individual features are used.

Taylor, would you be open to such a change?

@taylorotwell taylorotwell merged commit a8def08 into laravel:5.6 Jun 4, 2018
@staudenmeir staudenmeir deleted the sql-server-json branch June 4, 2018 17:19
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.

None yet

3 participants