Elements runtime reference / Local SQL

duckdb

Use the Element request-local DuckDB connection for local SQL, joins, dataframe registration, and table-shaped Element output.

Signatuur

def run(..., duckdb): duckdb.execute(sql, parameters=None)

Doel

Use the Element request-local DuckDB connection for local SQL, joins, dataframe registration, and table-shaped Element output.

Aliases and imports

  • duckdb.execute
  • duckdb.sql
  • duckdb.register
  • workspace

Payloadformaat

Use these fields as the Python call arguments or keyword payload for this helper.

{
  "entrypoint": "def run(params, duckdb, workspace): ...",
  "localDatabase": "{workspace}/element.duckdb",
  "tableOutput": {
    "table": "totals"
  }
}
FieldDescription
duckdbNamed entrypoint parameter injected as a duckdb.DuckDBPyConnection backed by {workspace}/element.duckdb.
workspaceOptional named entrypoint parameter with the writable scratch directory for the current run.
methodsNormal DuckDBPyConnection methods such as execute, sql, register, from_df, read_csv, and read_parquet.

Return payload

{
  "table": "totals"
}

Voorbeeld

def run(params, duckdb, workspace):
    duckdb.execute(
        "CREATE TABLE totals AS SELECT 1 AS id, ? AS value",
        [params["value"]]
    )
    return {"table": "totals"}

Scope-notities