Is there a shorter way to check if PGResult is empty?

I use pg stone to talk with PostgreSQL with Ruby. Is there a better way to check for results other than using res.ntuples == 0 ?

 conn = PGconn.connect config cmd = "select * from labels inner join labels_mail using(label_id) " + "where labels_mail.mail_id = $1 and labels.name = $2" res = conn.exec(cmd, [mail_id, mailbox]) if res.ntuples == 0 # <=== is there a better way to check this? cmd = "insert into labels_mail (mail_id, label_id) values ($1, $2)" conn.exec(cmd, [mail_id, label_id(mailbox)]) end 
+6
source share
1 answer

ntuples , typo? zero? faster and more concise to use zero? than == 0

 if res.num_tuples.zero? 
+5
source

Source: https://habr.com/ru/post/886254/


All Articles