Skip to content

Conversation

@pyramation
Copy link
Collaborator

Summary

Fixes inconsistent quoting in PL/pgSQL function bodies by using QuoteUtils from pgsql-deparser for schema-qualified type names.

Problem: When deparsing PL/pgSQL functions, type names in DECLARE sections were having all quotes stripped, leading to inconsistent output:

  • CREATE FUNCTION "constructive_encrypted".set(...) (quoted by pgsql-deparser)
  • v_secret constructive_encrypted.encrypted_secrets (unquoted by plpgsql-deparser)

Solution: For schema-qualified types (containing a dot), the deparser now uses QuoteUtils.quoteTypeDottedName() from pgsql-deparser for proper identifier quoting. Simple types preserve original behavior for round-trip consistency.

Key changes:

  • Import QuoteUtils from pgsql-deparser
  • Add isSchemaQualifiedType() to detect types with dots outside quotes
  • Add parseQualifiedTypeName() to parse dotted type names into parts
  • Handle array suffixes (e.g., []) separately from base type quoting

Review & Testing Checklist for Human

  • Test with constructive-db: After publishing/linking this package, run pnpm run generate:constructive in constructive-db and verify schema-qualified types like constructive_encrypted.encrypted_secrets are now consistently quoted
  • Verify edge cases: Test with escaped quotes in identifiers (e.g., "my""schema"."type") and array types with schema qualification (e.g., schema.type[])
  • Check %rowtype/%type references: Verify these special PL/pgSQL type references still work correctly (they bypass the new quoting logic)

Notes

  • All 58 plpgsql-deparser tests pass, including 190 round-trip fixtures
  • The fix intentionally only applies to schema-qualified types to avoid breaking round-trip consistency for simple types

Link to Devin run: https://app.devin.ai/sessions/f93a8b1ba9e54876a87e854e782a06ef
Requested by: @pyramation

For schema-qualified types (e.g., schema.typename), the deparser now uses
QuoteUtils from pgsql-deparser for proper identifier quoting. This ensures
consistent quoting behavior between the SQL deparser and PL/pgSQL deparser.

Changes:
- Import QuoteUtils from pgsql-deparser
- Add isSchemaQualifiedType() to detect types with dots
- Add parseQualifiedTypeName() to parse dotted type names
- Update deparseType() to use QuoteUtils.quoteTypeDottedName() for
  schema-qualified types
- Preserve original format for simple types to maintain round-trip consistency
- Handle array type suffixes (e.g., []) separately from the base type
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 14f097e into main Jan 8, 2026
18 checks passed
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.

2 participants