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

Support JSON data type #562

Open
HoneyryderChuck opened this issue Sep 24, 2024 · 3 comments
Open

Support JSON data type #562

HoneyryderChuck opened this issue Sep 24, 2024 · 3 comments

Comments

@HoneyryderChuck
Copy link

MS SQL Server seems to have support for JSON data types. Would it be possible to support it via tinyTDS? Reported in sequel as well

@andyundso
Copy link
Member

could be possible, but it is not straight-forward.

  1. freetds needs to support it. we rely on dbcoltype which tells us the column type in MSSQL and we can select the proper Ruby type to convert the value into. usually, there is a constant defined here in the freetds docs that would describe it, but I do not see anything here that would indicate support for this new JSON type.
  2. in tiny_tds, we will have to map it out. I assume you would expect tiny_tds to return a hash, right?
  3. This feature seems to be in preview and for Azure only, which makes it hard for us to develop and test. I would suggest we wait until the feature is no longer considered a preview (API is stable). maybe there will be a SQL Server 2025 release where this JSON data type will be included, which would make it much easier for us.

@HoneyryderChuck
Copy link
Author

thx for the answer! It makes sense to wait 👍

@Michoels
Copy link

Michoels commented Dec 18, 2024

For now I've been doing this by using NVACHAR(MAX) with a valid JSON check constraint:

-- assuming `my_table` with a column `metadata`
ALTER TABLE my_table
ADD CONSTRAINT my_table_metadata_must_be_json CHECK (ISJSON(metadata, OBJECT)=1);

This approach does not provide the more efficient binary storage the native JSON type provides.

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

No branches or pull requests

3 participants