Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does PRQL support SQL FILTER clauses? #4928

Unanswered
jcuenod asked this question in Q&A
Discussion options

Filter is overloaded here, so to be clear, I am referring to this kind of filter clause: https://www.sqlite.org/windowfunctions.html#the_filter_clause

In the sqlite docs, they have this example:

SELECT c, a, b, group_concat(b, '.') FILTER (WHERE c!='two') OVER (
 ORDER BY a
) AS group_concat
FROM t1 ORDER BY a;

This is a bit convoluted because it's also part of a window function. A simpler example is:

SELECT
 year,
 group_concat(title, ', ') FILTER (WHERE genre = 'comedy') as comedies,
 group_concat(title, ', ') FILTER (WHERE genre = 'drama') as dramas
FROM movies
GROUP BY year;

Is there PRQL that would compile to that SQL?

You must be logged in to vote

Replies: 1 comment 3 replies

Comment options

No, unfortunately not at the moment.

TBH this is the first I've heard of it. Is this exclusively a sqlite feature? It seems similar in some ways to QUALIFY...

You must be logged in to vote
3 replies
Comment options

I've used it in Clickhouse and DuckDB before. I see that it's also available in Postgres.

See https://modern-sql.com/feature/filter

Comment options

Ah great, that is nice. Particularly in a simple aggregate like DuckDB allows.

I think this could be great to include in PRQL in some way. There's a very old issue which seems like it could be reassessed: #82

We'd need to think of the PRQL semantics — we would really want it to be consistent with the existing structure. Possibly the examples in that issue could work; would need to think more.

Comment options

Yes, that's exactly the kind of thing I'm wondering about (I think the case ... when syntax is actually just an alternative for the same thing)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /