Skip to content

Commit c644ee1

Browse files
authored
sql/catalog: Fix comparison of pg_catalog types (#637)
Fixes #538
1 parent 5099cb2 commit c644ee1

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE FUNCTION f(x TIMESTAMPTZ) RETURNS void AS '' LANGUAGE sql;
2+
CREATE FUNCTION f(x timestamp with time zone) RETURNS void AS '' LANGUAGE sql;
3+
4+
-- name: F :one
5+
SELECT f(1);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"name": "querytest",
7+
"schema": "query.sql",
8+
"queries": "query.sql"
9+
}
10+
]
11+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# package querytest
2+
query.sql:1:1: relation "f" already exists

internal/sql/catalog/catalog.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,17 @@ func sameType(a, b *ast.TypeName) bool {
9292
if a.Catalog != b.Catalog {
9393
return false
9494
}
95-
if a.Schema != b.Schema {
95+
// The pg_catalog schema is searched by default, so take that into
96+
// account when comparing schemas
97+
aSchema := a.Schema
98+
bSchema := b.Schema
99+
if aSchema == "pg_catalog" {
100+
aSchema = ""
101+
}
102+
if bSchema == "pg_catalog" {
103+
bSchema = ""
104+
}
105+
if aSchema != bSchema {
96106
return false
97107
}
98108
if a.Name != b.Name {

0 commit comments

Comments
 (0)