Search code examples
postgresqllangchain

How to connect to postgreSQL in langchain and make schema


I want to use langchain's SQLAgent with my database PostgreSQL, the default schema is public, I want to use my schema like 'my_schema', what should I do?

I've tried splicing search_path=my_schema after the connection address but I get an error message: no parameters defined


Solution

  • You can use two ways for use schema

    1. Using search_path like below (documents)
    SET search_path TO my_schema,public;
    

    After set search path using SHOW search_path; to show your search path

    1. Using schema name behind table or DDL object
    select * from my_schema.table
    
    create table my_schema.test (...)