pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

functionCallRegex does not match quoted identifiers in dependency detection

Open tianzhou opened this issue 3 months ago • 0 comments

Description

functionCallRegex in internal/diff/diff.go uses pattern [a-z_][a-z0-9_$]* which does not match double-quoted identifiers like "MyFunc"(col). This affects all callers of referencesNewFunction():

  • Column defaults
  • Generated column expressions
  • CHECK constraints
  • Expression index columns
  • Partial index WHERE clauses

Impact

If a user creates a function with a case-sensitive name (e.g., CREATE FUNCTION "MyFunc"(...)) and references it in any of the above contexts, the dependency ordering may place the table before the function, causing CREATE INDEX/ALTER TABLE to fail at apply time.

Notes

  • In practice this is rare: PostgreSQL normalizes unquoted identifiers to lowercase
  • Only affects case-sensitive function names created with double quotes
  • Identified during PR #570 review (Greptile comment)

Suggested fix

Extend functionCallRegex to optionally match quoted identifiers: "[^"]+"

tianzhou avatar Aug 31 '26 06:08 tianzhou