@@ -299,7 +299,32 @@ void table_storage::load_table_metadata()
299299 PushActiveSnapshot (GetTransactionSnapshot ());
300300 pushed_snapshot = true ;
301301 }
302+ // Restore the original search_path so unqualified names resolve correctly
303+ std::string saved_search_path;
304+ if (!entry.search_path .empty ()) {
305+ const char * current_sp = GetConfigOption (" search_path" , true , false );
306+ if (current_sp != nullptr ) {
307+ saved_search_path = current_sp;
308+ }
309+ StringInfoData sp_sql;
310+ initStringInfo (&sp_sql);
311+ appendStringInfo (&sp_sql,
312+ " SELECT pg_catalog.set_config('search_path', %s, true)" ,
313+ quote_literal_cstr (entry.search_path .c_str ()));
314+ SPI_execute (sp_sql.data , true , 0 );
315+ pfree (sp_sql.data );
316+ }
302317 SPI_execute (entry.ddl_sql .c_str (), false , 0 );
318+ // Restore the session's original search_path
319+ if (!entry.search_path .empty ()) {
320+ StringInfoData restore_sql;
321+ initStringInfo (&restore_sql);
322+ appendStringInfo (&restore_sql,
323+ " SELECT pg_catalog.set_config('search_path', %s, true)" ,
324+ quote_literal_cstr (saved_search_path.c_str ()));
325+ SPI_execute (restore_sql.data , true , 0 );
326+ pfree (restore_sql.data );
327+ }
303328 if (pushed_snapshot) {
304329 PopActiveSnapshot ();
305330 }
0 commit comments