Database

Load CSV To Postgres

Load a CSV file into a PostgreSQL database. It could be combined with an Upload element, allowing end-users to upload CSV files directly into a specified table in a PostgreSQL database.

Parameters:

  • Asset ID Select: Choose the target PostgreSQL database. This selection determines where the CSV data will be loaded.

  • Table Name: Specify the name of the table in the PostgreSQL database where the CSV data will be loaded.

  • File Path: Provide the path to the CSV file you wish to upload.

  • Create Table If Absent: Activate this option to allow the system to automatically create a new table in the PostgreSQL database if the specified table name does not already exist. This feature helps in situations where the target table is yet to be set up.

  • Safe Mode: Enabling Safe Mode treats all columns in the CSV as text data. This mode is useful for preventing data type mismatches and errors during the upload process, especially when the exact data types of the CSV columns are unknown or varied.

  • Schema Detection Sample: This feature automatically detects and aligns the schema of the CSV file with the corresponding table in the PostgreSQL database. By default, the schema detection samples the first 1000 rows of the CSV file. This aids in accurately mapping CSV columns to the database table columns, reducing the risk of data inconsistencies.

Load JSON To Postgres

Load a JSON file into a PostgreSQL database. It could be combined with an Upload element, allowing end-users to upload JSON files directly into a specified table in a PostgreSQL database.

Parameters:

  • Asset ID Select: Choose the target PostgreSQL database.

  • Table Name: Specify the name of the table in the PostgreSQL database where the JSON data will be loaded.

  • File Path: Provide the path to the JSON file you wish to upload.

  • Create Table If Absent: Activate this option to allow the system to automatically create a new table in the PostgreSQL database if the specified table name does not already exist. This feature helps in situations where the target table is yet to be set up.

  • Safe Mode: Enabling Safe Mode treats all columns as text data. This mode is useful for preventing data type mismatches and errors during the upload process.

  • Schema Detection Sample: This feature automatically detects and aligns the schema of the CSV file with the corresponding table in the PostgreSQL database. By default, the schema detection samples the first 1000 records of the JSON file.

Example: Upload CSV to Postgres

Combining Upload and the Load CSV To Postgres API, you can build service for users to upload csv and preview them. This example serves as one of our template Upload CSV template, which you can find in the app builder.

  1. Add An Upload element

  2. Select event Upload Successfully

  3. (Optional) Use Generate Unique ID to get a table name and save it in app data

  4. Add the "Load CSV To Postgres" action. Use the path of the first uploaded file as the Path parameter.

  5. (Optional) Add a "Set Text" action to display a message indicating whether the operation was successful.

Last updated