civis.io.export_to_civis_file

civis.io.export_to_civis_file(sql, database, job_name=None, client=None, credential_id=None, polling_interval=None, hidden=True, csv_settings=None)[source]

Store results of a query to a Civis file

Parameters:
sql : str, optional

The SQL select string to be executed.

database : str or int

Execute the query against this database. Can be the database name or ID.

job_name : str, optional

A name to give the job. If omitted, a random job name will be used.

client : civis.APIClient, optional

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

credential_id : str or int, optional

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

polling_interval : int or float, optional

Number of seconds to wait between checks for query completion.

hidden : bool, optional

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

csv_settings : dict, optional

A dictionary of csv_settings to pass to civis.APIClient.scripts.post_sql().

Returns:
fut : CivisFuture

A future which returns the response from civis.APIClient.scripts.get_sql_runs() after the sql query has completed and the result has been stored as a Civis file.

See also

civis.io.read_civis
Read directly into memory without SQL.
civis.io.read_civis_sql
Read results of a SQL query into memory.
civis.io.civis_to_csv
Write directly to a CSV file.
civis.io.civis_file_to_table
Upload a Civis file to a Civis table

Examples

>>> sql = "SELECT * FROM schema.table"
>>> fut = export_to_civis_file(sql, "my_database")
>>> file_id = fut.result()['output'][0]["file_id"]