prql icon indicating copy to clipboard operation
prql copied to clipboard

count_distinct this => COUNT(DISTINCT t.*)

Open jangorecki opened this issue 2 years ago • 2 comments
trafficstars

What's up?

I noticed that

count_distinct this

translates to

COUNT(DISTINCT this) OVER ()`

I would expect it to translate into

COUNT(DISTINCT t.*)

(where t is table name)


One thing is extra OVER () which AFAIR is discussed in another issue, so lets not focus on this here.

I am filling this issue with a focus of translating this into t.*, which is valid postgres syntax.

http://sqlfiddle.com/#!17/d8c19/4

create table t1 (a1 integer, a2 integer);
insert into t1 values (1, 2);
insert into t1 values (1, 2);
insert into t1 values (1, 3);
select count(a1) from t1;
select count(*) from t1;
select count(distinct a1) from t1;
select count(distinct t1.*) from t1;

Gives

3
3
1
2

jangorecki avatar Oct 08 '23 07:10 jangorecki

I agree re compiling to COUNT(DISTINCT t.*).

Do we know whether other DBs support this?

max-sixty avatar Oct 16 '23 18:10 max-sixty

I am aware if any, and postgres requires table alias prefix to star, star alone won't work.

jangorecki avatar Oct 16 '23 19:10 jangorecki