Conversation
Casting an array type OID to regtype exposes its catalog name: OID 1016 displays as _int8 instead of bigint[]. The OID is correct, but the built-in branch of performIntToOidCast attaches the name from PGName(). Use SQLStandardName() to format built-in regtype values. Its existing array handling formats the element type and appends [], so integer and floating-point arrays receive their canonical SQL names. Scalar aliases also use SQL names, while vector and pseudo-type names retain their special handling. User-defined types still go through resolveOID for search-path-aware qualification. Distinguish oid.T_any from anyelement in the shared formatter. Both belong to AnyFamily, but must retain distinct names when used by the regtype cast. Add SQL expression regressions covering array names, scalar aliases, pseudo-types, vectors, OID preservation, NULL and zero. Add an exact-name test for the shared pseudo-type formatter. Fixes cockroachdb#97456 Release note (bug fix): Fixed the names displayed when casting built-in type OIDs to regtype. Array types now use SQL names such as bigint[] instead of internal catalog names such as _int8. Scalar types use their corresponding SQL names, such as integer for int4.
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
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.
Fixes #97456.
Casting an array type OID to
regtypecurrently exposes the internal catalog name instead of the SQL type name. For example:This returns
_int8; PostgreSQL returnsbigint[]. The OID itself is correct: casting the result back tooidstill gives1016. The discrepancy is in the name attached to theregtypevalue.performIntToOidCastresolves built-in type OIDs throughtypes.OidToType, then usesPGName()when constructing the result. That method supplies catalog names, including the underscore-prefixed array names. The built-in branch already documents that it should return SQL-standard names, but the formatter did not implement that behavior.This change uses
SQLStandardName()at that point. The existing formatter derives an ordinary array name from its element type's SQL name and appends[], so_int8becomesbigint[],_int4becomesinteger[], and_float8becomesdouble precision[]. Reusing the type formatter also handles scalar aliases consistently:int4displays asintegerandint8asbigint. This is preferable to stripping an underscore, which would still leave catalog spellings such asint8in the result. The formatter already has separate cases forint2vector,oidvector, andanyarray.There is one accompanying correction in the shared formatter.
anyandanyelementboth belong toAnyFamily, which previously always formatted asanyelement. Checking foroid.T_anykeeps their names distinct when the cast starts using this formatter.The cast still constructs the result with the original OID and
regtypesemantic type. Built-in types continue to use the existing lookup, and user-defined types continue throughresolveOID, including its search-path-aware qualification. No catalog entries or type identities change.Regression coverage includes the reported array OID, integer-to-
regtypecasts, an OID round trip, several other array element types, scalar aliases, pseudo-types, vector types, NULL, and the zero OID. The SQL expression cases run through both the optimized and non-optimized paths ofTestEval. A separate type-package test checks the exact names ofany,anyelement, andanyarray.Validation:
//pkg/sql/sem/eval:eval_testand//pkg/sql/types:types_testtargets pass locally.8812064a015d2faf99d3fc7e15880f94042954b0: the cast cases expose catalog names, and the type formatter returnsanyelementforany.crlfmt;git diff --checkpasses. The package tests used--norun_validations; the repository-wide test suite and full lint/generation checks were not run.Release note (bug fix): Fixed the names displayed when casting built-in type OIDs to
regtype. Array types now use SQL names such asbigint[]instead of internal catalog names such as_int8. Scalar types use their corresponding SQL names, such asintegerforint4.