Skip to content

Commit e27e1d9

Browse files
authored
Put schema in quotes for postgres driver (#2436)
* Put schema in quotes for postgres driver * Add tests
1 parent 8a256ce commit e27e1d9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/driver/sqlx_postgres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl SqlxPostgresConnector {
7979
let set_search_path_sql = options
8080
.schema_search_path
8181
.as_ref()
82-
.map(|schema| format!("SET search_path = {schema}"));
82+
.map(|schema| format!("SET search_path = \"{schema}\""));
8383
let lazy = options.connect_lazy;
8484
let mut pool_options = options.sqlx_pool_options();
8585
if let Some(sql) = set_search_path_sql {

tests/connection_tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,23 @@ pub async fn connection_ping_closed_postgres() {
140140

141141
ctx.delete().await;
142142
}
143+
144+
#[sea_orm_macros::test]
145+
#[cfg(feature = "sqlx-postgres")]
146+
pub async fn connection_with_search_path_postgres() {
147+
let ctx = TestContext::new("connection_with_search_path").await;
148+
149+
let base_url = std::env::var("DATABASE_URL").unwrap();
150+
let mut opt = sea_orm::ConnectOptions::new(format!("{base_url}/connection_with_search_path"));
151+
opt
152+
// The connection pool has a single connection only
153+
.max_connections(1)
154+
// A controlled connection acquire timeout
155+
.acquire_timeout(std::time::Duration::from_secs(2))
156+
.set_schema_search_path("schema-with-special-characters");
157+
158+
let db = sea_orm::Database::connect(opt).await;
159+
assert!(db.is_ok());
160+
161+
ctx.delete().await;
162+
}

0 commit comments

Comments
 (0)