Skip to content

feat: Support SQL ARRAY init from typed literals#26622

Open
alexander-beedie wants to merge 1 commit intopola-rs:mainfrom
alexander-beedie:sql-typed-array-literals
Open

feat: Support SQL ARRAY init from typed literals#26622
alexander-beedie wants to merge 1 commit intopola-rs:mainfrom
alexander-beedie:sql-typed-array-literals

Conversation

@alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Feb 19, 2026

Closes #18713.

Can now handle typed literals in SQL ARRAY declarations.

Example

import polars as pl

pl.sql(
    """
    SELECT
      -- typed temporal literals
      ARRAY[DATE '1969-07-20'] AS dt,
      ARRAY[TIMESTAMP '1999-12-31 00:15:25'] AS dtm,
      
      -- using equivalent cast syntax
      ARRAY['08:30:00'::time, '23:59:59'::time] AS tm_cast,
      
      -- other literal casts
      ARRAY[100::bigint, -50::bigint] AS i64_cast,
      ARRAY[['42'::int16], ['-7'::int16], ['0'::int16]] AS str_to_int_arr,
    """,
    eager=True,
)
# shape: (1, 5)
# ┌──────────────┬───────────────────────┬──────────────────────┬────────────┬───────────────────┐
# │ dt           ┆ dtm                   ┆ tm_cast              ┆ i64_cast   ┆ str_to_int_arr    │
# │ ---          ┆ ---                   ┆ ---                  ┆ ---        ┆ ---               │
# │ list[date]   ┆ list[datetime[μs]]    ┆ list[time]           ┆ list[i64]  ┆ list[list[i16]]   │
# ╞══════════════╪═══════════════════════╪══════════════════════╪════════════╪═══════════════════╡
# │ [1969-07-20] ┆ [1999-12-31 00:15:25] ┆ [08:30:00, 23:59:59] ┆ [100, -50] ┆ [[42], [-7], [0]] │
# └──────────────┴───────────────────────┴──────────────────────┴────────────┴───────────────────┘

@github-actions github-actions bot added A-sql Area: Polars SQL functionality enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Feb 19, 2026
@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 89.24731% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.40%. Comparing base (4929540) to head (85aa3bc).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-sql/src/sql_expr.rs 89.13% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #26622      +/-   ##
==========================================
+ Coverage   81.37%   81.40%   +0.02%     
==========================================
  Files        1794     1794              
  Lines      244998   245061      +63     
  Branches     3079     3079              
==========================================
+ Hits       199379   199482     +103     
+ Misses      44833    44793      -40     
  Partials      786      786              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-sql Area: Polars SQL functionality enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trying to create array of dates fails - SQL interface

1 participant

Comments