Queer European MD passionate about IT
Parcourir la source

COALESCE to avoid null rows from null fields

Davte il y a 6 ans
Parent
commit
ada5458368
2 fichiers modifiés avec 17 ajouts et 3 suppressions
  1. 1 1
      davtelepot/__init__.py
  2. 16 2
      davtelepot/custombot.py

+ 1 - 1
davtelepot/__init__.py

@@ -7,7 +7,7 @@ __author__ = "Davide Testa"
 __email__ = "davte@libero.it"
 __credits__ = "Marco Origlia"
 __license__ = "GNU General Public License v3.0"
-__version__ = "1.4.0"
+__version__ = "1.4.1"
 __maintainer__ = "Davide Testa"
 __contact__ = "t.me/davte"
 

+ 16 - 2
davtelepot/custombot.py

@@ -1940,10 +1940,24 @@ class Bot(telepot.aio.Bot, Gettable):
                             """SELECT telegram_id, MAX(name) name
                             FROM (
                                 SELECT telegram_id,
+                                    COALESCE(
                                     first_name || ' ' || last_name ||
-                                    ' (' ||username || ')' AS name
+                                    ' (' || username || ')',
+                                    username,
+                                    first_name || ' ' || last_name,
+                                    last_name,
+                                    first_name
+                                    ) AS name
                                 FROM users
-                                WHERE first_name || last_name || username
+                                WHERE COALESCE(
+                                    first_name || last_name || username,
+                                    first_name || username,
+                                    last_name || username,
+                                    first_name || last_name,
+                                    username,
+                                    last_name,
+                                    first_name
+                                )
                                 LIKE '%{u}%'
                                 UNION ALL
                                 SELECT telegram_id, name