Skip to content

Conversation

@MarcoGorelli
Copy link
Member

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ”§ Optimization
  • πŸ“ Documentation
  • βœ… Test
  • 🐳 Other

Related issues

  • Related issue #<issue number>
  • Closes #<issue number>

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below

@MarcoGorelli MarcoGorelli added the enhancement New feature or request label Oct 29, 2025
@MarcoGorelli MarcoGorelli marked this pull request as ready for review October 30, 2025 17:32
narwhals/sql.py Outdated
CREATE TABLE "{name}"
({dtypes});
""")
return from_native(CONN.table(name))
Copy link
Member Author

Choose a reason for hiding this comment

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

πŸ€” maybe this could return a subclass of LazyFrame which has a to_sql method, with an optional dependency on sqlglot if people want to pass dialect != 'duckdb' or pretty=True

Comment on lines +14 to +26
try:
import duckdb # ignore-banned-import
except ImportError as _exc: # pragma: no cover
msg = (
"`narwhals.sql` requires DuckDB to be installed.\n\n"
"Hint: run `pip install -U narwhals[sql]`"
)
raise ModuleNotFoundError(msg) from _exc

CONN = duckdb.connect()
TZ = DeferredTimeZone(
CONN.sql("select value from duckdb_settings() where name = 'TimeZone'")
)
Copy link
Member Author

Choose a reason for hiding this comment

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

I think (hope?) that in the future we could make a narwhals-sqlglot or narwhals-substrait plugin and use that here. But for now, I think using DuckDB for this is quite nice

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant