Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

Learn more about PostgreSQL Import Integration.

You can export job results from Treasure Data to your existing PostgreSQL instance.

For sample workflows of PostgreSQL, view Treasure Boxes.

Continue to the following topics:

Table of Contents


  • Basic knowledge of Treasure Data, including the TD Toolbelt.

  • A PostgreSQL instance.

Use the TD Console to Create Your Connection

Create a New Connection

Complete the field values to create a new connection.

Enter the required credentials for your new PostgreSQL connection. Set the following parameters:

  • Host: The host information of the source database, such as an IP address.

  • User: Username to connect to the source database.

  • Password: Password to connect to the source database.

  • Use SSL: Check this box to connect using SSL

    • Require a valid SSL certificate?: Require that a valid SSL certificate is presented on the connection.

Configure Results Export to Your PostgreSQL Instance

Export from Treasure Data uses queries. You create or reuse a query. In the query, you configure the data connection.

Excerpt Include
PD:Exporting Your Query Data to Your Destination
PD:Exporting Your Query Data to Your Destination

Set the Export Result Parameters

Database name: The name of the database you are transferring data to. (Ex. your_database_name)

Table: The table to which you would like to export the data.

Output mode. Different methods to upload the data.

  • Append (default): The append mode is the default that is used when no mode option is provided in the URL. In this mode, the query results are appended to the table. If the table does not exist, it is created. This mode is atomic.

  • Replace: The replace mode consists of replacing the entire content of an existing table with the resulting output of the query. If the table does not exist yet, a new table is created. The replace mode achieves atomicity (so that a consumer of the table always has consistent data) by performing the following three steps in a single transaction:

    1. Create a temporary table;

    2. Write to the temporary table;

    3. Replace the existing table with the temporary table using ALTER TABLE RENAME.

  • Truncate: the system first truncates the existing table, then inserts the query results. If the table does not exist yet, a new table is created. This mode is atomic.

  • Update: a row is inserted unless it would cause a duplicate value in the columns specified in the “unique” parameter: in such case, an update is performed instead. The “unique” parameter is required when using the update mode. This mode is atomic.

Insert Method. This option controls how the data is written into the Postgres table. The default method is copy; it is also the recommended method for most situations.

  • Copy (default): Data is first stored in a temporary file on the server, then written to Postgres using a COPY transaction. This method is faster than INSERT, so it is useful when handling a large amount of data.

  • Insert: Data is written to Postgres using ‘INSERT’ statements. This is the most reliable and compatible method and it is recommended for most situations.

Schema: Defines the schema where the target table is located. If not specified, the default schema is to be used. The default schema depends on the user’s “search_path” setting but it is usually “public”.

Foreign Data Wrapper: This option controls whether or not a data wrapper is used to store the data. The default is none and should work in most instances.

      • None (default) - No foreign-data wrapper.

      • Cstore - used when columnar storage is required/enabled on the destination table.

Run Query and Check Results

Run the query with Output Results selected. If the query completes successfully, you see the results in the PostgreSQL database and table that you specified when entering the transfer details.

Optional: Use of Scheduled Jobs for Output

You can use Scheduled Jobs with Result Output, to periodically write the output result to a PostgreSQL instance that you specify.

Excerpt Include
PD:Scheduling Jobs Using TD Console
PD:Scheduling Jobs Using TD Console

Optional: Configure Export Results in Workflow

Within Treasure Workflow, you can specify the use of this data connector to output data.

Code Block
timezone: UTC

    database: sample_datasets

  td>: queries/sample.sql
  result_connection: your_connections_name
   database: database_name
   table: table_name
   mode: append
   set_role:new role

Read about using data connectors in a workflow to export data. See an example workflow.