Marko Zadravec
Marko Zadravec

Reputation: 8730

Getting data from schema in psycopg2

I try to connect to Postgres database inside my Python app. I use psycopg2 library.

If I execute select statement like this:

cursor.execute("""select schema_name from information_schema.schemata;""")
rows = cursor.fetchall()
print(rows)

and I get :

[('DB_FZ',), ('DB_FZ_TEMP',), ...]

but if I execute statement

cursor.execute("""select * from DB_FZ.d_results;""")
rows = cursor.fetchall()
print(rows)

I get error

psycopg2.ProgrammingError: schema "db_fz" does not exist
LINE 1: select * from DB_FZ.d_results;

What could be wrong?

Upvotes: 2

Views: 2713

Answers (1)

klin
klin

Reputation: 121594

The schema name is in uppercase, you should put it in double quotes:

cursor.execute("""select * from "DB_FZ".d_results;""")

See also Are PostgreSQL column names case-sensitive?

Upvotes: 2

Related Questions