From 4337eb225774b34564f95241b29eb339034660aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20S=C3=B8e?= Date: Tue, 7 Jan 2025 13:14:31 +0100 Subject: [PATCH] fix: use current_schema for postgres TableExists, if schema is unspecified (#884) --- internal/dialect/dialectquery/postgres.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/dialect/dialectquery/postgres.go b/internal/dialect/dialectquery/postgres.go index 21ba63b36..580c1a9c6 100644 --- a/internal/dialect/dialectquery/postgres.go +++ b/internal/dialect/dialectquery/postgres.go @@ -50,7 +50,7 @@ func (p *Postgres) TableExists(tableName string) string { q := `SELECT EXISTS ( SELECT 1 FROM pg_tables WHERE schemaname = '%s' AND tablename = '%s' )` return fmt.Sprintf(q, schemaName, tableName) } - q := `SELECT EXISTS ( SELECT 1 FROM pg_tables WHERE tablename = '%s' )` + q := `SELECT EXISTS ( SELECT 1 FROM pg_tables WHERE (current_schema() IS NULL OR schemaname = current_schema()) AND tablename = '%s' )` return fmt.Sprintf(q, tableName) }