Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
9 changes: 9 additions & 0 deletions internal/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@ func (c *Config) addEnvVars() error {
}
c.Cloud.AuthToken = authToken

defaultSchema := os.Getenv("SQLC_DEFAULT_SCHEMA")
if defaultSchema != "" {
for i, sql := range c.SQL {
if sql.DefaultSchema == "" {
c.SQL[i].DefaultSchema = defaultSchema
}
}
}

return nil
}
9 changes: 6 additions & 3 deletions internal/engine/postgresql/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion internal/engine/postgresql/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading