Skip to content

Conversation

treysp
Copy link
Collaborator

@treysp treysp commented Sep 5, 2025

Consider a cast to a built-in data type, where the type is quoted: 1::"integer"

We currently parse this into the correct underlying type for dialects that allow this AND support user-defined types (like tsql).

This PR allows us to parse correctly for dialects that do not support user-defined types (like redshift).

self.raise_error("Unexpected identifier", self._prev)
try:
tokens = self.dialect.tokenize(identifier.name)
except TokenError:
Copy link
Collaborator

@VaggelisD VaggelisD Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we self.raise_error(...) here? Otherwise, we'll now silently continue on

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is intentional. See previous threads & Slack.

Comment on lines +5317 to +5321
if self.dialect.SUPPORTS_USER_DEFINED_TYPES:
this = self._parse_user_defined_type(identifier)
else:
self._retreat(self._index - 1)
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nit] Could we revert the if/elif/else chain to reduce some of the indentation?

Comment on lines +808 to +809
self.validate_identity('1::"int"', "CAST(1 AS INT)")
assert parse_one('1::"int"', read="postgres").to.is_type(exp.DataType.Type.INT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the generic parse_one here if we read into the same dialect as in the testing file.

We can grab the AST as ast = self.validate_identity(...) or do ast = self.parse_one(...) which will set the appropriate dialect.

Comment on lines +703 to +704
self.validate_identity('1::"int"', "CAST(1 AS INTEGER)")
assert parse_one('1::"int"', read="redshift").to.is_type(exp.DataType.Type.INT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@georgesittas
Copy link
Collaborator

Merging this as is, will clean up tests afterwards.

@georgesittas georgesittas merged commit 3408de0 into main Sep 8, 2025
6 checks passed
@georgesittas georgesittas deleted the trey/quoted-types branch September 8, 2025 11:16
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.

3 participants