question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hasura + timescaledb on pg11 > Upserts not working anymore

See original GitHub issue

Hi there,

I recently switched Hasura backend db from timescale/timescaledb:1.2.1-pg10 to timescale/timescaledb:1.2.1-pg11.

As described in this issue on Timescaledb github, when doing an UPSERT operation on an hypertable (through Graphql-engine), I’m now faced with this error: ERROR: hypertables do not support ON CONFLICT statements that reference constraints.

To workaround this, Guys at Timescaledb advised me to instead of mentioning the constraint name (like does graphql-engine statement) :

INSERT INTO "data" ( "timestamp", "uuid" ) VALUES ( "2019-03-06T16:46:46.988Z", "9db6dbe1-cd14-1d17-38c0-4d4a36679fd6" ) ON CONFLICT ON CONSTRAINT "data_pkey" DO NOTHING RETURNING *

To explicitly mention column names (involved in the constraint): screenshot from 2019-03-07 08-48-46

Even though I believe the “design issue” is more on Timescaledb side, I’d be interested to hear your input on this > would that make sense for Hasura to change the way it’s working now, If not, why?

Many thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:30 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
waterdrop01commented, Feb 27, 2021

Hello, @0x777 @marionschleifer @tirumaraiselvan, did you guys plan to release a fix to this bug? It’s soon going to be 2 years this issue is open. Reproducing should be quite straightforward:

  1. docker pull timescale/timescaledb:latest-pg12
  2. docker pull hasura/graphql-engine
  3. Connect to timescaledb (which is a postgres instance + an extension) and run CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; as well as CREATE SCHEMA "schema1"; & CREATE TABLE "schema1"."table1" ("id" int AS IDENTITY PRIMARY KEY,"value" text NOT NULL, "timestamp" timestamp with time zone NOT NULL); and finally run SELECT create_hypertable('schema1.table1', 'timestamp'); to convert schema.table1 to a timescale “hypertable”.
  4. Send this mutation through Hasura:
mutation upsert_schema1_table1(
    $objects: [schema1_table1_insert_input!]!
    $update_columns: [schema1_table1_update_column!]!
  ) {
    insert_schema1_table1(
      objects: $objects
      on_conflict: { constraint: table1_pkey, update_columns: $update_columns }
    ) {
      returning {
        id
        value
       timestamp
      }
    }
  }

with these query variables:

{
  "objects": {
    "id": 1,
    "value": "value",
    "timestamp": "2021-02-26T12:00:00+00:00",
  },
  "update_columns": ["id", "value", "timestamp"]
}

This will throw an “ON CONFLICT ON CONSTRAINT” error, as with Hypertables one can’t reference a primary key by its name, but only by its column names:

Screenshot from 2021-02-27 11-01-02

Your help would be much appreciated ❤️

4reactions
ondrejspilkaABBcommented, Jan 12, 2021

Hello, any resolution to this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timescale DB 2.0 with Hasura and GraphQL
TimescaleDB 2.0 is a major upgrade that has many improvements. ... This article will share some known issues and workarounds.
Read more >
Postgres: Upsert mutation | Hasura GraphQL Docs
However, they work slightly differently. An upsert mutation is used in the case when it's not clear if the respective row is already...
Read more >
Using TimescaleDB with Hasura GraphQL
Use Hasura GraphQL on top of TimescaleDB to build powerful real-time dashboards in minutes.
Read more >
Using Hasura Cloud with a Timescale Postgres database
... which we recommend, follow steps 1 and 2 below. If you're self-hosting a Hasura instance and already have a project running, skip...
Read more >
TimescaleDB | Time-series Data | Hasura GraphQL
TimescaleDB is the first open-source time-series database that natively supports full SQL ... Top PostgreSQL Flavours and Extensions that work with Hasura.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found