Skip to content

Conversation

@martint
Copy link
Member

@martint martint commented Nov 20, 2025

Standard SQL supports static method calls on types via the :: operator. While this syntax is generally incompatible with PostgreSQL shorthand cast syntax, there's a subset of that can be safely repurposed to support that functionality.

The SQL specification defines static method calls as:

   <static method invocation> ::=
      <path-resolved user-defined type name> <double colon> <method name>
      [ <SQL argument list> ]

where <path-resolved user-defined type name> translates to:

   <user-defined type name> ::=
      [ <schema name> <period> ] <qualified identifier>

To support casts, we need to extend the rule to support arbitrary expressions as the target of the invocation. To disambiguate a static method call from a cast, we distinguish between type-producing expressions and expressions that produce regular values. For the latter, if the method matches the name of a well-known type, we treat it as a cast. Otherwise, the expression assumed to be a static method call and fail the evaluation with a "not yet supported" error.

One limitation is that casts are only supported for simple types. Parametric types are not yet supported, but it wouldn't be too hard to add. Types whose name don't match the syntax of SQL function calls are not supported either and will be harder to support. That will require introducing type-producing expressions into the language and making types first-class expressions.

Fixes #23795

Release notes

(x) Release notes are required, with the following suggested text:

## General
* Add support to simplified cast expressions with the `::` operator. ({issue}`23795`)

@cla-bot cla-bot bot added the cla-signed label Nov 20, 2025
@martint martint requested review from findepi and kasiafi November 20, 2025 22:10
Standard SQL supports static method calls on types via the :: operator.
While this syntax is generally incompatible with PostgreSQL shorthand cast
syntax, there's a subset of that can be safely repurposed to support that
functionality.

The SQL specification defines static method calls as:

   <static method invocation> ::=
      <path-resolved user-defined type name> <double colon> <method name>
      [ <SQL argument list> ]

where <path-resolved user-defined type name> translates to:

   <user-defined type name> ::=
      [ <schema name> <period> ] <qualified identifier>

To support casts, we need to extend the rule to support arbitrary expressions
as the target of the invocation. To disambiguate a static method call from
a cast, we distinguish between type-producing expressions and expressions that
produce regular values. For the latter, if the method matches the name of a
well-known type, we treat it as a cast. Otherwise, the expression assumed
to be a static method call and fail the evaluation with a "not yet supported"
error.

One limitation is that casts are only supported for simple types. Parametric
types are not yet supported, but it wouldn't be too hard to add. Types whose
name don't match the syntax of SQL function calls are not supported either
and will be harder to support. That will require introducing type-producing
expressions into the language and making types first-class expressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Cast operator ::

2 participants