Queer European MD passionate about IT
Browse Source

COALESCE to avoid null rows from null fields

Davte 6 years ago
parent
commit
ada5458368
2 changed files with 17 additions and 3 deletions
  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