Skip to content

SqlContext ​

Namespace: Polars.CSharp

A context for executing SQL queries against DataFrames and LazyFrames.

Polars supports a subset of ANSI SQL. The query is converted into a logical plan and optimized/executed by the Polars engine.

Constructors & Static Methods ​

SqlContext ​

Create a new SQL Context.

csharp
public SqlContext()

Instance Methods ​

Execute ​

Execute a SQL query.

csharp
public LazyFrame Execute(string query)

Parameters

NameTypeDescription
querystringThe SQL query string.

Returns: A new LazyFrame representing the query result.


GetTables ​

Get the names of all registered tables, in sorted order.

csharp
public string[] GetTables()

Returns: An array of registered table names.


Register ​

Register a LazyFrame as a table in the SQL context.

Register a DataFrame as a table (convenience method). Converts DataFrame to LazyFrame internally.

csharp
public void Register(string tableName, LazyFrame lf)
public void Register(string tableName, DataFrame df)

Parameters

NameTypeDescription
tableNamestringThe name to use in SQL queries (e.g., 'SELECT * FROM tableName')
lfLazyFrameThe LazyFrame to register.
dfDataFrame-

UnRegister ​

UnRegister a LazyFrame as a table.

csharp
public void UnRegister(string tableName)

Parameters

NameTypeDescription
tableNamestring-

Released under the MIT License. Powered by the Polars Rust core & Apache Arrow.