diff --git a/internal/compiler/engine.go b/internal/compiler/engine.go index d263637d9f..7156e310a1 100644 --- a/internal/compiler/engine.go +++ b/internal/compiler/engine.go @@ -44,7 +44,7 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err c.catalog = dolphin.NewCatalog() case config.EnginePostgreSQL: c.parser = postgresql.NewParser() - c.catalog = postgresql.NewCatalog() + c.catalog = postgresql.NewCatalog(combo.Package.DefaultSchema) if conf.Database != nil { if conf.Analyzer.Database == nil || *conf.Analyzer.Database { c.analyzer = analyzer.Cached( diff --git a/internal/config/config.go b/internal/config/config.go index 5bfa506b00..866524e0c6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -111,6 +111,7 @@ type SQL struct { Name string `json:"name" yaml:"name"` Engine Engine `json:"engine,omitempty" yaml:"engine"` Schema Paths `json:"schema" yaml:"schema"` + DefaultSchema string `json:"default_schema" yaml:"default_schema"` Queries Paths `json:"queries" yaml:"queries"` Database *Database `json:"database" yaml:"database"` StrictFunctionChecks bool `json:"strict_function_checks" yaml:"strict_function_checks"` diff --git a/internal/engine/postgresql/catalog.go b/internal/engine/postgresql/catalog.go index 3c262122a2..19085f96ed 100644 --- a/internal/engine/postgresql/catalog.go +++ b/internal/engine/postgresql/catalog.go @@ -8,12 +8,15 @@ func toPointer(x int) *int { return &x } -func NewCatalog() *catalog.Catalog { - c := catalog.New("public") +func NewCatalog(defaultSchema string) *catalog.Catalog { + if defaultSchema == "" { + defaultSchema = "public" + } + c := catalog.New(defaultSchema) c.Schemas = append(c.Schemas, pgTemp()) c.Schemas = append(c.Schemas, genPGCatalog()) c.Schemas = append(c.Schemas, genInformationSchema()) - c.SearchPath = []string{"pg_catalog"} + c.SearchPath = []string{"pg_catalog", defaultSchema} c.LoadExtension = loadExtension return c } diff --git a/internal/engine/postgresql/catalog_test.go b/internal/engine/postgresql/catalog_test.go index 875ea7e458..96fdc0a752 100644 --- a/internal/engine/postgresql/catalog_test.go +++ b/internal/engine/postgresql/catalog_test.go @@ -149,7 +149,7 @@ func TestUpdateErrors(t *testing.T) { t.Fatal(err) } - c := NewCatalog() + c := NewCatalog("") err = c.Build(stmts) if err == nil { t.Log(test.stmt)