civis.io.query_civis

civis.io.query_civis(sql: str, database: str | int, client: APIClient | None = None, credential_id: int | None = None, preview_rows: int = 10, polling_interval: int | float | None = None, hidden=True) CivisFuture[source]

Execute a SQL statement as a Civis query.

Run a query that may return no results or where only a small preview is required. To execute a query that returns a large number of rows, see read_civis_sql().

Parameters:
sqlstr

The SQL statement to execute.

databasestr or int

The name or ID of the database.

clientcivis.APIClient, optional

If not provided, an civis.APIClient object will be created from the CIVIS_API_KEY.

credential_idint, optional

The ID of the database credential. If None, the default credential will be used.

preview_rowsint, optional

The maximum number of rows to return. No more than 1000 rows can be returned at once.

polling_intervalint or float, optional

Number of seconds to wait between checks for query completion.

hiddenbool, optional

If True (the default), this job will not appear in the Civis UI.

Returns:
resultsCivisFuture

A CivisFuture object.

Examples

>>> import civis
>>> run = civis.io.query_civis(sql="DELETE schema.table", database='database')
>>> run.result()  # Wait for query to complete