[Python] How to set postgres and psycopg2 so that it always searches the schema without having...

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I have a postgres DB where I have run this command to avoid having to mention schema explicitly:

    ALTER DATABASE ibkr_trader SET search_path TO public;

    However, when I connect using psycopg2 in python, I still have to type this to access my tables:

    select count(*) from "public"."MY_TABLE"

    I even tried setting options in psycopg2.connect but it didn't work:

    return psycopg2.connect(
    dbname=self.dbname,
    user=self.user,
    password=self.password,
    port=self.port,
    host=self.host,
    options="-c search_path=public"
    )


    What is the most elegant way to set this network up so that I don't have to type "public":"MY_TABLE" for each query? I do not have any other schemas in my DB and I don't wanna have to mention it explicitly.

    Continue reading...

Compartilhe esta Página