Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(postgres)!: Parse empty bracketed ARRAY with cast #4679

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

VaggelisD
Copy link
Collaborator

Fixes #4674

  • AST before:
>>> ast = sqlglot.parse_one("SELECT ARRAY[]::INT[]", dialect="postgres")
>>> ast
Select(
  expressions=[
    Cast(
      this=DataType(
        this=Type.ARRAY,
        expressions=[
          DataType(this=Type.ARRAY, nested=True)],
        nested=True),
      to=DataType(
        this=Type.ARRAY,
        expressions=[
          DataType(this=Type.INT, nested=False)],
        nested=True))])

  • AST after
>>> ast = sqlglot.parse_one("SELECT ARRAY[]::INT[]", dialect="postgres")
>>> ast
Select(
  expressions=[
    Cast(
      this=Array(
        ),
      to=DataType(
        this=Type.ARRAY,
        expressions=[
          DataType(this=Type.INT, nested=False)],
        nested=True))])

Note how before, the ARRAY[] would be confused into nesting itself even though on Postgres it's a 1-D array:

psql> SELECT ARRAY[1]::INT[];
 array
-------
 {1}
(1 row)

@georgesittas georgesittas merged commit 1a91913 into main Jan 29, 2025
7 checks passed
@georgesittas georgesittas deleted the vaggelisd/psql_empty_arr branch January 29, 2025 15:03
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.

Bug in Empty Array Parsing from postgres to duckdb
2 participants