> ## Documentation Index
> Fetch the complete documentation index at: https://docs.graphext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# export_to_sql

> Export a given dataset to a specified SQL database. 

This step uploads the given dataset to a table identified by the name provided in this step's parameters.
This table either exists already or it's going to be created in the SQL database configured in your SQL integration.
If you have several SQL integrations configured, this step will use the last one you added.
Further customization such as entry or table overwriting behavior can be achieved through parameters.

## Usage

The following examples show how the step can be used in a recipe.

<Accordion title="Examples" icon="code" defaultOpen="true">
  <Tabs>
    <Tab title="Example 1">
      Export dataset to a SQL database table

      ```stan theme={null}
      export_to_sql(ds, {"integration": "MY_SQL_INTEGRATION", "table_name": "enriched_customers"})
      ```
    </Tab>

    <Tab title="Example 2">
      Append rows to an existing SQL table

      ```stan theme={null}
      export_to_sql(ds, {"integration": "MY_SQL_INTEGRATION", "table_name": "event_logs", "if_exists": "append"})
      ```
    </Tab>

    <Tab title="Signature">
      General syntax for using the step in a recipe. Shows the inputs and outputs the step is expected to receive and will produce respectively. For futher details see sections below.

      ```stan theme={null}
      export_to_sql(ds: dataset, {
          "param": value,
          ...
      })
      ```
    </Tab>
  </Tabs>
</Accordion>

## Inputs & Outputs

The following are the inputs expected by the step and the outputs it produces. These are generally
columns (`ds.first_name`), datasets (`ds` or `ds[["first_name", "last_name"]]`) or models (referenced
by name e.g. `"churn-clf"`).

<Accordion title="Inputs" icon="right-to-bracket">
  <ParamField path="ds" type="dataset" required>
    Dataset to be uploaded.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket" />

## Configuration

The following parameters can be used to configure the behaviour of the step by including them in
a json object as the last "input" to the step, i.e. `step(..., {"param": "value", ...}) -> (output)`.

<Accordion title="Parameters" defaultOpen="true" icon="sliders">
  <ParamField path="integration" type="string" required>
    ID of the integration you'd like to use.
  </ParamField>

  <ParamField path="table_name" type="string" required>
    The name of the table you want to upload data to.
  </ParamField>

  <ParamField path="if_exists" type="string" default="fail">
    The preferred method for handling existing tables.

    * 'Fail' if there is another table with the same name. The default value is 'fail' to prevent you from accidentally losing your data or compromising a table's structure in your database.
    * 'Replace' if you want to override the existing table. Keep in mind this option deletes your previous data.
    * 'Append' if you want to append the dataset's rows to the table.

    Values must be one of the following:

    * `fail`
    * `replace`
    * `append`
  </ParamField>
</Accordion>
