Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:5.6from
staudenmeir:sql-server-json
Jun 4, 2018
Merged

[5.6] Add JSON SELECT queries to SQL Server#24397
taylorotwell merged 1 commit into
laravel:5.6from
staudenmeir:sql-server-json

Conversation

@staudenmeir

Copy link
Copy Markdown
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

sisve commented Jun 1, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

sisve commented Jun 1, 2018 via email

Copy link
Copy Markdown
Contributor

@staudenmeir

staudenmeir commented Jun 1, 2018

Copy link
Copy Markdown
Contributor Author

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.

3 participants