fukamachi / sxql

An SQL generator for Common Lisp.
BSD 3-Clause "New" or "Revised" License
355 stars 32 forks source link

Add examples of COUNT(*) and how to use 'fields' #47

Open jzumer opened 5 years ago

jzumer commented 5 years ago

As per the title. (fields (:count :*)) works, however. The examples in the readme don't use fields in their statements, so one or the other seems out of date or bugged.

fukamachi commented 5 years ago

It's intended, and seems to be a wrong example. What part of the README?

jzumer commented 5 years ago

It's in the select section:

(select (:sex (:count :*)) (from :person) (group-by :sex)) ;=> #<SXQL-STATEMENT: SELECT sex, COUNT(*) FROM person GROUP BY sex>

(select (:sex (:as (:count :*) :num)) (from :person) (group-by :sex) (order-by (:desc :num))) ;=> #<SXQL-STATEMENT: SELECT sex, COUNT(*) AS num FROM person GROUP BY sex ORDER BY num DESC>

I think this behavior is somewhat confusing (having an explicit example showing how (:count :*) doesn't resolve to COUNT(*), and how to get to that would certainly help).

fukamachi commented 5 years ago

I don’t get what’s wrong with it and not sure what you’re supposed to. It’s a list of columns. You mean we should always use ‘fields’?

2019年2月6日(水) 9:58 Jeremie Zumer notifications@github.com:

It's in the select section:

(select (:sex (:count : )) (from :person) (group-by :sex)) ;=> #<SXQL-STATEMENT: SELECT sex, COUNT() FROM person GROUP BY sex>

(select (:sex (:as (:count :

*) :num)) (from :person) (group-by :sex) (order-by (:desc :num))) ;=>

<SXQL-STATEMENT: SELECT sex, COUNT(*) AS num FROM person GROUP BY sex

ORDER > BY num DESC>

I think this behavior is somewhat confusing (having an explicit example in select would certainly help).

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/fukamachi/sxql/issues/47#issuecomment-460864776, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFhytDQnUIu6NXa-IG9x9PmSjQoqQdVks5vKijEgaJpZM4aj5z9 .

jzumer commented 5 years ago

Sorry if it's not clear, I'm trying to say that it's not very obvious that to get COUNT(*) we should use (fields (:count :*)) and not (:count :*), mostly because of the text I quote above.

fukamachi commented 5 years ago

Okay, thank you for yor clarification. I agree with the less documentation and somewhat confusing. I'll try to add some examples.

On Wed, Feb 6, 2019 at 11:12 AM Jeremie Zumer notifications@github.com wrote:

Sorry if it's not clear, I'm trying to say that it's not very obvious that to get COUNT() we should use (fields (:count :)) and not (:count :*), mostly because of the text I quote above.

  • If this is as intended, then I think it would be good to make that clear in the readme (in particular, point out that (:a (:count :)) gives a, COUNT() but (:count :) gives count, ).
  • If not, then it would be more consistent to have, for example, (select (:sex (fields (:count :))) ...) and (select (:sex (:as (fields (:count :)) :num)) ...) instead of the current forms.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fukamachi/sxql/issues/47#issuecomment-460877808, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFhykjMV043y-NnzoeSbr4NPHicldaXks5vKjoUgaJpZM4aj5z9 .