How do I read a table belonging to another user on pgadmin?

Viewed 34

I'm trying to run the following code to read a table from another user on PgAdmin (he has already granted me select permission).It works when I try to get tables created by my own user, but not for other ones.

import pandas as pd
from sqlalchemy import create_engine
def recupera_bd(tablename):
    param_dic = {
    "host"      : "PP-APPS",
    "database"  : "blabla",
    "user"      : "ltsurumaki",
    "password"  : "******"
}

    connect = "postgresql+psycopg2://%s:%s@%s:5432/%s" % (
        param_dic['user'],
        param_dic['password'],
        param_dic['host'],
        param_dic['database']
    )       
    
    engine = create_engine(connect) 
    df = pd.read_sql(tablename, con=engine)
    return df 

hbp = recupera_bd('consolidado_pnl')
1 Answers

You have to specify the schema name too schema2.tablename, or to have schema2 in your search_path

hbp = recupera_bd('schema2.consolidado_pnl')
Related