fix(Migrator): use lowercase current_schema() for PG14 compatibility - #349
Open
feiguoL wants to merge 1 commit into
Open
fix(Migrator): use lowercase current_schema() for PG14 compatibility#349feiguoL wants to merge 1 commit into
feiguoL wants to merge 1 commit into
Conversation
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+).
feiguoL
force-pushed
the
fix-current-schema-pg14
branch
from
August 10, 2026 08:16
34492e8 to
accd563
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
PostgreSQL 14 raises
syntax error at or near "CURRENT_SCHEMA" (SQLSTATE 42601)when the migrator executesDROP INDEXand other DDL that referencesCurrentSchema().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 — becausetests_all.shrunsgo get -u -t ./...and picks upv1.6.2.Fix
Use the lowercase function form
current_schema(), which is valid across all supported PostgreSQL versions (13+).Verification
go build ./...— OKgo vet ./...— OKgo test ./...— passesThe gorm
postgres:14, oldstablejob is expected to turn green once this lands and a new tag is released.