Insert/Upsert Method

Overview

The Insert method in QueryDeck allows you to add new records to your database. The Upsert method is a combination of "update" and "insert," allowing you to either insert a new record or update an existing one if a conflict occurs. This ensures data consistency and prevents duplicate entries when using unique constraints.

With QueryDeck’s Insert/Upsert method, you can:

  • Add new records to your database.

  • Handle conflicts using the on_conflict clause.

  • Update records if they already exist based on specified constraints.

Using the Insert or Upsert query:

1. Select the Base Table

  • From the left pane in the demo app, choose a base table to use. For this example, we will use the customers table.

2. Configure the Query Method

  • In the left pane:

    • Change the Method to Insert or Upsert.

  • Update the Route Name if required.

3. Save the Endpoint

  • Click on the Save button at the bottom of the left pane.

  • Your endpoint for Insert/Upsert is now ready.

Testing

  • Copy the endpoint URL by clicking it in the top right corner

  • Open Postman:

    • Paste the endpoint URL into the input field.

    • Change the request method to POST.

Add a Sample Request Body

  • Under the Body tab in Postman:

    • Select raw as the body type.

    • Paste a sample request body in JSON format. For example:

Send the Request

  • Click on the Send button in Postman.

  • You will receive a response indicating that the query was successful.

You have now successfully created and tested your Insert/Upsert query.

Last updated