Querydeck Docs
  • 👋Welcome to Query Deck
  • Getting Started
    • 😃Get Started With QueryDeck
      • Quickstart With QueryDeck
    • How It Works?
  • REST
    • Select Method
      • Joins
      • Sorting
        • Ascending/ Descending ordering
        • Dynamic Sorting
      • Filter
        • Dynamic Filtering
        • Groups
        • Exists clause
      • Pagination
        • Offset
        • Limit
    • Insert/Upsert Method
      • Nested Inserts (Joins)
      • Conflicting Columns
    • Update Method
      • Filters
    • Delete Method
    • Authentication
    • Authorization
    • Select by Id
  • GraphQL
    • Introduction to GraphQL in QueryDeck
    • Enabling GraphQL for Columns in QueryDeck
  • Testing Endpoints
Powered by GitBook
On this page
  • Implementation
  • Testing
  1. REST
  2. Insert/Upsert Method

Conflicting Columns

PreviousNested Inserts (Joins)NextUpdate Method

Last updated 3 months ago

When inserting data, conflicting columns may arise due to database constraints, such as unique keys or primary keys. QueryDeck provides mechanisms to handle such conflicts gracefully using the on_conflict clause. This ensures that duplicate records do not cause the operation to fail and allows you to define specific actions when conflicts occur.

Implementation

Choose the button with your table name (here, customers). This is used to manipulate column display

In the pop up that opens, choose conflicting columns

Now choose a constraint of your choice

Then select columns you want to include

Then click on save, to write the changes

Testing

Copy the URL endpoint from the top right corner

Now open postman and paste the link in the URL input bar, and change the method to POST

Under the "body" tab, click on "raw" and then use a request body. Here's an example body

{
  "customer": [
    {
      "email": "sample@example.com",
      "active": 1,
      "store_id": 1,
      "last_name": "Doe",
      "activebool": true,
      "address_id": 1,
      "first_name": "John",
      "create_date": "2023-01-01",
      "last_update": "2023-01-01T12:00:00.000Z"
    }
  ],
  "on_conflict": {
    "constraint": "customers_email_key",
    "update_columns": ["last_name", "active", "last_update"]
  }
}

Hit send to place the request

Here is an example response of what we should get