count
only non-NULL rows in PRQL
#4395
Replies: 5 comments 2 replies
-
You want something like this? from bar
filter foo != null
select {count this} |
Beta Was this translation helpful? Give feedback.
-
Sorry for the delayed response: I wanted to think carefully about what I was asking... This question is an outgrowth of #4384 ( But here I'm asking a bit of a "language feature" question: if I already have a column that contains values or NULLs, is there a way to do it in one step (without the For example, here is a query on sample data. The Playground shows the result of the SQL query as [2, 2, 2].
But if I manually change the generated SQL to end with Would this be a useful feature? That is, distinguish between |
Beta Was this translation helpful? Give feedback.
-
@kgutwin That's a good solution. I see this could be made into a function If they are not too special purpose, it would be terrific if you would share your other S-strings. We can collect them as a series of "pro tips". Thanks! |
Beta Was this translation helpful? Give feedback.
-
And here's where the differences between SQL engines will bite you... That syntax works for DuckDB, but SQLite doesn't support a |
Beta Was this translation helpful? Give feedback.
-
A couple workarounds: @snth notes that you can @kgutwin suggests using an S-string in a function: @kgutwin also suggests these functions |
Beta Was this translation helpful? Give feedback.
-
From #4384: It appears that
count
always compiles to COUNT(*), which always includes NULL rows. Is there a way to "count only non-NULL rows" in PRQL? That would be equivalent to SQL's COUNT(foo)... (I didn't see anything in the Book that seemed to do this.) Thanks.Beta Was this translation helpful? Give feedback.
All reactions