From 5a0ad8cc533dffccef78697e5b5d9e45665c0a91 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Tue, 24 Dec 2024 00:17:43 +0000 Subject: [PATCH] Fix schema search path --- src/driver/sqlx_postgres.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index b43ccd52f..725276893 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -1,7 +1,7 @@ use futures::lock::Mutex; use log::LevelFilter; use sea_query::Values; -use std::{future::Future, pin::Pin, sync::Arc}; +use std::{fmt::Write, future::Future, pin::Pin, sync::Arc}; use sqlx::{ pool::PoolConnection, @@ -76,10 +76,13 @@ impl SqlxPostgresConnector { ); } } - let set_search_path_sql = options - .schema_search_path - .as_ref() - .map(|schema| format!("SET search_path = \"{schema}\"")); + let set_search_path_sql = options.schema_search_path.as_ref().map(|schema| { + let mut string = "SET search_path = ".to_owned(); + for schema in schema.split(',') { + write!(&mut string, "\"{schema}\"").unwrap(); + } + string + }); let lazy = options.connect_lazy; let mut pool_options = options.sqlx_pool_options(); if let Some(sql) = set_search_path_sql {