Table Operations
Function | Description |
|---|---|
Create a new table and its columns from a SQL query executed against an existing table. | |
Remove specific rows of data from a table using an (optional) constraint. | |
Deletes the specified table, unregistering it. | |
Returns the Polars execution plan for a given SQL query. | |
Returns a list of all tables registered in the given context. | |
Unnest one or more arrays as columns in a new table object. | |
Remove all data from a table without actually deleting it. |
CREATE TABLE
Create a new table from a sequence of column definitions, a SQL query executed against an existing table, or create an empty table from the schema of an existing table.
Example:
CREATE TABLE tbl(colx VARCHAR, coly DATE, colz ARRAY<DOUBLE>)
CREATE TABLE new_table AS SELECT * FROM existing_table WHERE value > 42
CREATE TABLE new_table LIKE existing_table
DELETE
Remove specific rows from a table using an (optional) constraint. Omitting the constraint deletes all rows, equivalent to TRUNCATE.
Example:
DELETE FROM some_table WHERE value < 0
DROP TABLES
Deletes the specified table, unregistering it. Dropping a table that does not exist raises an error unless the optional IF EXISTS clause is given, in which case the statement is a no-op.
Example:
DROP TABLE actual_table DROP TABLE IF EXISTS possible_table
EXPLAIN
Returns the Polars execution plan for a given SQL query.
Example:
EXPLAIN SELECT * FROM some_table
SHOW TABLES
Returns a list of all tables registered in the given context.
Example:
SHOW TABLES
UNNEST
Unnest one or more arrays as columns in a new table object.
Example:
SELECT * FROM
UNNEST(
[1, 2, 3, 4],
['ww','xx','yy','zz'],
[23.0, 24.5, 28.0, 27.5]
) AS tbl (x,y,z)
TRUNCATE
Remove all data from a table without deleting the table itself. Truncating a table that does not exist raises an error unless the optional IF EXISTS clause is given, in which case the statement is a no-op.
Example:
TRUNCATE TABLE actual_table TRUNCATE TABLE IF EXISTS possible_table
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/sql/table_operations.html