Skip to content

fix(Migrator): use lowercase current_schema() for PG14 compatibility - #349

Open
feiguoL wants to merge 1 commit into
go-gorm:masterfrom
feiguoL:fix-current-schema-pg14
Open

fix(Migrator): use lowercase current_schema() for PG14 compatibility#349
feiguoL wants to merge 1 commit into
go-gorm:masterfrom
feiguoL:fix-current-schema-pg14

Conversation

@feiguoL

@feiguoL feiguoL commented Aug 10, 2026

Copy link
Copy Markdown

Motivation

PostgreSQL 14 raises syntax error at or near "CURRENT_SCHEMA" (SQLSTATE 42601) when the migrator executes DROP INDEX and other DDL that references CurrentSchema().

The current code returns clause.Expr{SQL: "CURRENT_SCHEMA()"}. CURRENT_SCHEMA (uppercase) is a reserved keyword in PostgreSQL; PG14 parses the keyword first, then sees () as a syntax error. PG15+ tolerates it, but PG14 does not.

This broke the gorm CI matrix (postgres:14, oldstable) for every recent PR — see e.g. go-gorm/gorm#7837, go-gorm/gorm#7839, go-gorm/gorm#7840 — because tests_all.sh runs go get -u -t ./... and picks up v1.6.2.

Fix

Use the lowercase function form current_schema(), which is valid across all supported PostgreSQL versions (13+).

- return clause.Expr{SQL: "CURRENT_SCHEMA()"}, table
+ return clause.Expr{SQL: "current_schema()"}, table

Verification

  • go build ./... — OK
  • go vet ./... — OK
  • go test ./... — passes

The gorm postgres:14, oldstable job is expected to turn green once this lands and a new tag is released.

CURRENT_SCHEMA (uppercase) is a reserved keyword in PostgreSQL. When used
as CURRENT_SCHEMA() in DDL contexts like DROP INDEX, PostgreSQL 14 raises
'syntax error at or near CURRENT_SCHEMA' (SQLSTATE 42601) because it
parses the keyword first, not the function call.

Using lowercase current_schema() is the function form that works across all
supported PostgreSQL versions (13+).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant