Thread: Authorizing select count()
Hello,
Vik Fearing pointed out the inconsistency in the SQL Standard that imposes using count(*) (with a star) but row)number() without it.
Vik's point of view is that we should be able to use row_number with a star, which is already implemented in Postgres.
My point of view is we could add support for count(). It does not remove the compliance with the SQL Standard, it just adds an extra feature.
You will find enclosed a patch proposal to allow count to be used without a star. I, on purpose, decided not to document this behavior, maybe that's wrong.
Have a great day,
Lætitia
Attachment
On Wed, May 25, 2022 at 12:26:47PM +0200, Laetitia Avrot wrote: > You will find enclosed a patch proposal to allow count to be used without a > star. I, on purpose, decided not to document this behavior, maybe that's > wrong. This originates from 108fe47, most likely as part of this thread. The patch proposed by Sergey did not include this restriction, though: https://www.postgresql.org/message-id/Pine.LNX.4.64.0607241340090.19158%40lnfm1.sai.msu.ru Tom? -- Michael
Attachment
Michael Paquier <michael@paquier.xyz> writes: > On Wed, May 25, 2022 at 12:26:47PM +0200, Laetitia Avrot wrote: >> You will find enclosed a patch proposal to allow count to be used without a >> star. I, on purpose, decided not to document this behavior, maybe that's >> wrong. > This originates from 108fe47, most likely as part of this thread. I'm fairly sure that in the past we've considered this idea and rejected it, mainly on the grounds that it's a completely gratuitous departure from SQL standard. I quite agree that the syntax without star would be saner, but once we get into inventing "saner" variants of SQL syntax, where do we stop? And how much are we buying really? I definitely don't agree with doing it but not documenting it; that will just result in endless confusion. regards, tom lane
I wrote: > I'm fairly sure that in the past we've considered this idea and rejected > it, mainly on the grounds that it's a completely gratuitous departure > from SQL standard. After some more digging I found the thread that (I think) the "mere pedantry" comment was referring to: https://www.postgresql.org/message-id/flat/Pine.LNX.4.44.0604131644260.20730-100000%40lnfm1.sai.msu.ru There's other nearby discussion at https://www.postgresql.org/message-id/flat/4476BABD.4080100%40zigo.dhs.org (note that that's referring to the klugy state of affairs before 108fe4730) Of course, that's just a couple of offhand email threads, which should not be mistaken for graven stone tablets. But I still don't see much advantage in deviating from the SQL-standard syntax for COUNT(*). regards, tom lane