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

Use -> operator for SQLite JsonScalarExpression #30745

Merged
merged 1 commit into from
Apr 24, 2023

Conversation

roji
Copy link
Member

@roji roji commented Apr 23, 2023

Closes #30334

@roji roji requested a review from maumar April 23, 2023 11:15
@@ -126,56 +126,106 @@ private Expression VisitRegexp(RegexpExpression regexpExpression)
/// </summary>
protected override Expression VisitJsonScalar(JsonScalarExpression jsonScalarExpression)
{
if (jsonScalarExpression.Path.Count == 1
&& jsonScalarExpression.Path[0].ToString() == "$")
// TODO: This trims the leading $ PathSegment, which isn't actually part of the path (but rather path of the JSONPATH language
Copy link
Member Author

@roji roji Apr 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maumar note this - I think we should remove the $ path segment at the beginning, at the source... It's purely a SQL generation concern, and PostgreSQL would need to ignore it (since it doesn't use JSONPATH for this). Even for SQLite, when there's just a single (non-$) path segment, this PR does JsonColumn ->> 'Foo' (property) or JsonColumn ->> 1 (array), which is simpler and again doesn't need the $.

On a related note, when the JSON expression has no path segments, it shouldn't be created in translation - there's this piece of code here for ignoring/unwrapping it when it's empty.

Does that make sense? If so I can open a separate issue to do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

JSON/Sqlite: use -> and ->> where possible when traversing JSON, rather than json_extract
2 participants