import psycopg2
import psycopg2.extras


def get_data_from_postgres(conn, qry):
    """

    Gets a list of 'DictRows' from a PostgreSQL database. A DictRow can be indexed numerically or by column name, In other
    words it behaves like a list OR a dictionary object.

    :param conn: The database connection string
    :param qry: The SQL query which gets the data
    :return: The result set.
    """
    try:
        my_conn = psycopg2.connect(conn)
        cur = my_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)

        try:
            cur.execute(qry)
            c = cur.fetchall()
            cur.close()
            # self.result = c
            return c
        except psycopg2.Error as e:
            print(e)
            return False

    except psycopg2.OperationalError as e:
        print(e)
        return False