Search code examples
postgresqlpsycopg2amazon-rdspostgresql-9.4rds

psycopg2 change schema does not work


I am writing a simple python prog to connect and display results from Postgres table this is on AWS RDS. I have table mytest in public schema.

connection = psycopg2.connect(dbname='some_test',
                    user='user1',
                    host='localhost',
                    password='userpwd',
                    port=postgres_port)
cursor = connection.cursor()
cursor.execute("SET SEARCH_PATH TO public;")
cursor.execute("SELECT *  FROM mytest;")

But this throws an error

psycopg2.ProgrammingError: relation "mytest" does not exist

LINE 1: SELECT * FROM mytest;

Connection is successful and I can query other basetables like

SELECT table_name FROM information_schema.tables

It is just that I cannot change to any other schema. I googled and tried all kinds of SET SERACH_PATH and commit it and recreate cursor etc. but no use. I cannot query any other schema.


Solution

  • ALTER USER username SET search_path = schema1,schema2;
    

    After setting this the query works fine!