-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add support for JSONField #54
Conversation
django_snowflake/features.py
Outdated
# Could possibly use "OR" to check both cases but the number of ORs | ||
# need increases exponentially for nested lookups. | ||
'model_fields.test_jsonfield.TestQuerying.test_has_key_number', | ||
# null issue: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sfc-gh-mkeller I'm wondering if have you a sense of whether or not this issue and the below issues mentioning "needs to operate as" (where PARSE_JSON()
is needed on the right-hand side of the query) will be solved by snowflakedb/snowflake-connector-python#244? I don't know if it's possible to work around here until then.
Also, feel free to comment on any of the other failures here if you have any suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd make sense if you did "MODEL_FIELDS_NULLABLEJSONMODEL"."VALUE"[123]
if the key is an integer and do the "MODEL_FIELDS_NULLABLEJSONMODEL"."VALUE":"123"
if the key is a string.
The JSON standard only allows string keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your comment refers to test_has_key_number'
which I solved last night in the latest commit. I was actually asking about cases like this:
WHERE TO_JSON("MODEL_FIELDS_NULLABLEJSONMODEL"."VALUE":k) = '{"l": "m"}'
where the right-hand side parameter is treated as a string literal rather than as JSON.
A working version of this query is:
WHERE TO_JSON("MODEL_FIELDS_NULLABLEJSONMODEL"."VALUE":k) = PARSE_JSON('{"l": "m"}')
but I'm not sure this is feasible to implement here. I thought maybe when/if the Python connector gains awareness of VARIANT type, the first query might work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've documented this as a known limitation: #58.
# Not yet implemented in this backend. | ||
supports_json_field = False | ||
# TODO: Not yet implemented in this backend. | ||
supports_json_field_contains = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some other databases implement JSON_CONTAINS()
(@>
and <@
on PostgreSQL). Is it unsupported by Snowflake or did I miss an equivalent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can treat JSON columns as regular VARIANT
columns, like:
select *
from (
select parse_json(column1) as user
from (
select * from values
('{"name": "Luke", "age": 25}'),
('{"name": "Mark", "age": 35}')
)
) where user ilike '%luke%'
;
We don't have any special JSON variants of this as far as I know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we can (easily?) use regular expressions since the example code you gave will also match JSON keys. I'll call this unsupported, at least for now.
6d26ec1
to
7458602
Compare
SQLInsertCompiler.as_sql() is copied from Django, to be customized in the next commit adding support for inserting JSONField values.
Fixes #23