You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The where() mechanism described above is pretty much ideal. There's one fly in the ointment though. It is a primary design goal for the SLQ query language to imitate jq's query language where possible. And jq already has a similar mechanism: select()
$ jq '.[] | select(.id == "second")'
Ordinarily, we would just go with select() to align with jq. However, this is semantically ugly. It is unfortunate that jq chose select() instead of where(). For users coming from a SQL background, select means "SELECT these columns", not "select the rows that match this expression". That is to say, it seems likely that implementing select() to mean WHERE may confuse sq users.
As an unsatisfactory compromise, the first implementation will probably use where(), but will also allow the synonym select(). But I'm open to feedback on this.
The text was updated successfully, but these errors were encountered:
It's not a good suggestion where(...)It's too ugly.This suggestion should not be adopted.Should: 1. first test if there is a conditional statement, if there is, all the conditions are put together and must be in the front 2. if it so happens that there is only one field that you want to check, and the field is a comparative expression, figure out how to solve it by yourself, e.g.: @db '.table | true | .id>100' Don't see why you should complicate a simple problem.Ease of use is key for software.
Is your feature request related to a problem? Please describe.
The current mechanism to implement the
WHERE
clause has got problems.Currently, it's possible to write a
sq
query like this:$ sq '.actor | .actor_id > 10 | .actor_id, .first_name' ^^^ WHERE ^^^^
This becomes a SQL query:
We want to be able to implement the ability to select literal values, e.g.
$ sq '.actor | true, .first_name, 77, "hello"'
This would become:
So far, so good. But these literals could instead be expressions:
$ sq '.actor | .first_name, actor_id, .actor_id > 2'
Which becomes:
Result:
Let's simplify that query to this:
$ sq '.actor | .actor_id > 2'
Here's the problem. That query is ambiguous.
sq
can't tell which of these two SQL queries is wanted:Describe the solution you'd like
The
WHERE
clause mechanism needs to be explicit.$ sq '.actor | where(.actor_id > 2) | .actor_id > 2'
This would translate to:
Design choice:
where()
vsselect()
The
where()
mechanism described above is pretty much ideal. There's one fly in the ointment though. It is a primary design goal for the SLQ query language to imitate jq's query language where possible. And jq already has a similar mechanism:select()
$ jq '.[] | select(.id == "second")'
Ordinarily, we would just go with
select()
to align with jq. However, this is semantically ugly. It is unfortunate that jq choseselect()
instead ofwhere()
. For users coming from a SQL background,select
means "SELECT these columns", not "select the rows that match this expression". That is to say, it seems likely that implementingselect()
to meanWHERE
may confusesq
users.As an unsatisfactory compromise, the first implementation will probably use
where()
, but will also allow the synonymselect()
. But I'm open to feedback on this.The text was updated successfully, but these errors were encountered: