Skip to content

Commit 4337eb2

Browse files
authored
fix: use current_schema for postgres TableExists, if schema is unspecified (#884)
1 parent 779024d commit 4337eb2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

internal/dialect/dialectquery/postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (p *Postgres) TableExists(tableName string) string {
5050
q := `SELECT EXISTS ( SELECT 1 FROM pg_tables WHERE schemaname = '%s' AND tablename = '%s' )`
5151
return fmt.Sprintf(q, schemaName, tableName)
5252
}
53-
q := `SELECT EXISTS ( SELECT 1 FROM pg_tables WHERE tablename = '%s' )`
53+
q := `SELECT EXISTS ( SELECT 1 FROM pg_tables WHERE (current_schema() IS NULL OR schemaname = current_schema()) AND tablename = '%s' )`
5454
return fmt.Sprintf(q, tableName)
5555
}
5656

0 commit comments

Comments
 (0)