Post AZN7LAHpsyDtoLt0QS by snooze_cat@mstdn.social
 (DIR) More posts by snooze_cat@mstdn.social
 (DIR) Post #AZN6RbjMf8Hii7GqY4 by stux@mstdn.social
       2023-09-02T23:16:42Z
       
       0 likes, 0 repeats
       
       Stop using COUNT(id) to count rowshttps://www.youtube.com/watch?v=H6juZ8c_Nu8
       
 (DIR) Post #AZN7KyxvyclehRUSNU by glent@aus.social
       2023-09-02T23:26:45Z
       
       0 likes, 0 repeats
       
       @stux That's a very long video to say that "SELECT *" means all columns and "COUNT(*)" means any column, and they optimise as you'd expect.
       
 (DIR) Post #AZN7LAHpsyDtoLt0QS by snooze_cat@mstdn.social
       2023-09-02T23:26:49Z
       
       0 likes, 0 repeats
       
       @stux Thanks for sharing! I haven't written any SQL for a couple of years but still enjoy learning about it.
       
 (DIR) Post #AZN8EA9w3q49LKPqXQ by Aedius@lavraievie.social
       2023-09-02T23:36:39Z
       
       0 likes, 0 repeats
       
       @stux select count( distinct id ) just to be really sure 🤣
       
 (DIR) Post #AZN9lTHM5y1e9UKhyi by mikej@mastodon.online
       2023-09-02T23:54:00Z
       
       0 likes, 0 repeats
       
       @stux Except the query optimizer is going to ignore what you wrote and do it the fast way anyway, so don't actually worry about it that much.
       
 (DIR) Post #AZNkzHBdXzSb0U6W6S by marhoff@piaille.fr
       2023-09-03T06:50:59Z
       
       0 likes, 0 repeats
       
       @stuxAlso count(id) is dangerous when table have a multi-columns primary key. You'll end up with a partial count if specifing one column.This is a good advice but beware it was MySQL centered. A some point he used "show create table ..." but this is engine specific. (And I learned someting, i'm always a little sad that pg_dump is the only "easy" option for doing so in postgres) https://serverfault.com/questions/231952/is-there-an-equivalent-of-mysqls-show-create-table-in-postgresThe universal SQL advice yet remain "learn how your specific SQL engine optimizer work".