# Source SQL

<figure><img src="https://1671598980-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0muDd0LkZG6CmTQvGQ4D%2Fuploads%2FsWxNp1J28Uro4gbfcyjf%2FSource%20sql%20-%201.png?alt=media&#x26;token=f5cf1f2a-2a91-4274-8b34-f4ae1bd96ad4" alt=""><figcaption></figcaption></figure>

The **Source SQL** task allows you to run SQL queries directly on databases connected to Gaio DataOS.\
It is ideal for extracting, transforming, or importing data from external sources (such as relational databases) into your project for use in data flows, analysis, and dashboards.

***

## How to Use

### **1. Open the Task**

Navigate to: **Tasks > ETL > Source SQL**

***

### **2. Select a Database**

In the left-side panel:

* Select a database previously registered in the environment and released for your user ID.
* Once selected, all available tables from that source will be displayed.

***

### **3. Write the SQL Code**

In the **Code** tab:

* Type or paste your SQL query.
* You can use advanced SQL syntax, including `JOIN`, `WHERE`, `GROUP BY`, `CTEs`, and more.

{% hint style="info" %}
Use **Run query** to test the results before saving the task.
{% endhint %}

***

### **4. Settings (Settings Tab)**

<figure><img src="https://1671598980-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0muDd0LkZG6CmTQvGQ4D%2Fuploads%2FjV6YxMNg3JK8as0Afuch%2FSource%20sql%20-%202.png?alt=media&#x26;token=95e6b18b-9fd4-4fbf-a527-aa4a2ff1f63a" alt=""><figcaption></figcaption></figure>

* **Save on default repository:** Saves the query result as a table in the project’s local repository.
* **Incremental mode:** Only imports new records when applicable.
* **Field as string:** Converts all fields to text.
* **Create an empty table when no data:** Creates the table structure even if the query returns no data.
* **Raw imports:** Imports data without automatic formatting.
* **Auto columns (JDBC only):** Automatically detects column structure (JDBC connections only).
* **JSForce Bulk Mode (Salesforce only):** Optimizes performance for bulk imports from Salesforce.

{% hint style="warning" %}
These options are especially useful for managing schema and performance in external database integrations.
{% endhint %}

***

### **5. Columns Tab**

* This tab becomes available only if **Save on default repository** is enabled.
* Manually define column names and types for the resulting table if you don’t want them to be automatically detected.

***

### **6. Save and Run**

* Click **Save** to add the task to your flow.
* You can then link this step to additional tasks (such as transformation, visualization, or export).

***

#### &#x20;Use Cases

* Querying live data from an external source (e.g., MySQL, PostgreSQL, Oracle, SQL Server)
* Importing legacy system or ERP data via SQL
* Transforming data before ingestion directly through SQL
* Automating integrations with enterprise databases using custom queries
