You can use join for groups array and SELECT WHERE group IN groups for filter:
import psycopg2
def filter_groups(group_names):
try:
# connect to BD
connection = psycopg2.connect(
host="host",
user="user",
password="pass",
database="db_name"
)
except Exception as _ex:
print("[INFO] Connection error", _ex)
try:
with connection.cursor() as cursor:
placeholders = ','.join(['%s'] * len(group_names))
rsql = f"SELECT * FROM table_name WHERE groups IN ({placeholders})"
cursor.execute(rsql, group_names)
rows = cursor.fetchall()
cursor.close()
except Exception as _ex:
print("[INFO] Error while working with PostgreSQL", _ex)
if connection:
connection.close()
print("[INFO] PostgreSQL connection closed.")
return rows
character varying[]type (instead oftext?), or that you are getting an error when you try to define the function accepting or returning this data type. It'd be easier to work this out if you showed your samples and error messages.