> For the complete documentation index, see [llms.txt](https://docs.bdb.ai/data-pipeline-3/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bdb.ai/data-pipeline-3/components/writers/db-writer.md).

# DB Writer

The DB reader is a spark-based writer component which gives you capability to write data to multiple database sources.

All component configurations are classified broadly into the following sections:

* ​[​Basic Information​](/data-pipeline-3/components/component-base-configuration.md)​
* Meta Information
* ​[Resource Configuration​](/data-pipeline-3/components/resource-configuration.md)​
* ​[Connection Validation](https://docs.bdb.ai/7.6/data-pipeline/components/connection-validation)​

{% hint style="success" %}
*Please check out the given demonstration to configure the component.*
{% endhint %}

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fc39ZvXI46qjXzpN3rYAg%2Fuploads%2FgBcXWWdOXknp0JN4cgtZ%2F2023-10-30-18-01-35%20(online-video-cutter.com).mp4?alt=media&token=89aa1f64-b6f6-40da-a31a-19c12024a58a>" %}
***DB Writer configuration for ClickHouse driver***
{% endembed %}

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fc39ZvXI46qjXzpN3rYAg%2Fuploads%2FdSepVFheAHDMQ3matHLz%2F2023-09-04-18-46-34%20(online-video-cutter.com).mp4?alt=media&token=d3074c8c-2f23-4cc6-b81f-7a3137a59868>" %}
***Configuring DB Writer component for Redshift Driver***
{% endembed %}

### **Drivers Available**

<details>

<summary>Supported Drivers</summary>

* MySQL
* Oracle
* PostgreSQL
* MS-SQL
* ClickHouse
* Snowflake
* Redshift

</details>

{% hint style="info" %}
*<mark style="color:green;">**Please Note:**</mark>*&#x20;

* *The **ClickHouse** driver in the **Spark** components will use the **HTTP Port** and not the **TCP** port.*
* *It is always recommended to create the table before activating the pipeline to avoid errors as RDBMS has a strict schema and can result in errors.*
* When using the ***Redshift*** driver with a ***Boolean*** datatype in JDBC, the table is not created unless you pass the create table query.\
  Alternatively, you can use a column filter to convert a ***Boolean*** value to a ***String*** for the desired operation.
  {% endhint %}

### Save Modes <a href="#save-modes" id="save-modes"></a>

The RDBMS writer supports 3 save modes:

#### **Append**

As the name suggests it adds all the records without any validations.

#### **Overwrite**

This mode truncates the table and adds fresh records. after every run you will get records that are part of the batch process.

#### **Upsert**

This operation allows the users to insert a new record or update existing data into a table. For configuring this we need to provide the Composite Key.

The BDB Data Pipeline supports composite key based upsert, in case of composite key, we can specify the second key by using comma separator e.g., *key1, key2​.* It has now an option to **upload the spark schema in JSON format.** This can greatly improve the speed of the write operation as the component will ignore inferring schema and go with the provided schema.

<figure><img src="/files/tz1Zwk85nHVAbqRFlBcJ" alt=""><figcaption><p><em><strong>Meta information tab for DB Writer</strong></em></p></figcaption></figure>

* **Sort Column:** This field will appear only when ***Upsert*** is selected as ***Save mode***. If there are multiple records with the same composite key but different values in the batch, the system identifies the record with the latest value based on the Sort column. The Sort column defines the ordering of records, and the record with the highest value in the sort column is considered the latest.<br>

  <figure><img src="/files/Xb9yICwfv8ybhO8Ntt5r" alt=""><figcaption><p><em><strong>Sort Column in Upsert Mode for DB Writer (ClickHouse driver)</strong></em></p></figcaption></figure>

{% hint style="info" %}
*<mark style="color:green;">Please Note</mark>:*&#x20;

* Currently, the ***Sort column*** field is only available for the following drivers in the DB Writer: ***MSSQL**, **PostgreSQL**, **Oracle**, **Snowflake**, and **ClickHouse.***&#x20;
  {% endhint %}

* **Database name:** Enter the Database name.

* **Table name:** Provide a table name where the data has to be written.

* **Enable SSL:** Check this box to enable SSL for this components. Enable SSL feature in DB reader component will  appear only for three(3) drivers: ***MongoDB, PostgreSQL and ClickHouse***.

* **Certificate Folder:** This option will appear when the Enable SSL field is checked-in. The user has to select the certificate folder from drop down which contains the files which has been uploaded to the admin settings. Please refer the below given images for the reference.

* **Schema File Name:** Upload the Spark Schema in JSON format.

* ***Query:*** In this field, we can write a DDL for creating the table in database where the in-event data has to be written. For example, please refer the below image:

<figure><img src="/files/mRZdvnftJZ6eyVANSh9y" alt=""><figcaption><p><em><strong>Writing a DDL for creating a table in DB.</strong></em></p></figcaption></figure>

<figure><img src="/files/TCecuVWzqRfuLJ8iCAnI" alt=""><figcaption><p><em><strong>Meta Information fields of the DB writer (with SSL enabled)</strong></em> </p></figcaption></figure>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark>*&#x20;

In **DB Writer** component, the Save Mode for ClickHouse driver is as follows:

* **Append**: It will create a table in ClickHouse database with a table engine ***Stripelog***.
* **Upsert**: It will create a table in ClickHouse database with a table engine ***ReplacingMergeTree***.
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bdb.ai/data-pipeline-3/components/writers/db-writer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
