Python Forum

Full Version: formatting string and returning as geojson
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
sorry, it's my error. It was late last night and I messed up something in the db_query()
I will post the correct one when I get home
Actually, try this one - I changed line 35

def db_query():
    """ Connect to the PostgreSQL database server """
    # read connection parameters
    params = config()
    # connect to the PostgreSQL server
    print('Connecting to the PostgreSQL database...')
    with psycopg2.connect(**params) as conn:
        # create a cursor
        with conn.cursor() as cur:
            try:
                cur.execute("SELECT t.id, t.\"vendorField\" FROM transactions t WHERE t.\"vendorField\" LIKE 'geo%'")
                print("Rows returned: ", cur.rowcount)
                geo_data = cur.fetchall()
            except psycopg2.DatabaseError as db_error:
                print(db_error)
                geo_data = []
            finally:
                print('Database connection closed.')
    return geo_data
db_query() should not process data, it need to query the DB and just return data as tuple of tuples
If problem persist, I will look into it when I get home
Thank you, it works perfectly.
Really appreciated!
Pages: 1 2