TransWikia.com

Table as an Index?

Database Administrators Asked by akagixxer on October 28, 2021

PostgreSQL 11

Requirements:

  • Uniqueness must be guaranteed (not duplicated)
  • MUST not lose any data.

The data I get is NOT uniquely identified, so I am left with semantic comparison of the values to determine uniqueness.

E.g.

CREATE TABLE data.stuff
(
  recorded  BIGINT   NOT NULL,
  source_id INT      NOT NULL,
  key       TEXT     NOT NULL,
  value     TEXT     NOT NULL
  
  PRIMARY KEY (recorded, source_id, key, value)
);

INSERT INTO data.stuff (recorded, source_id, key, value)
VALUES (?, ?, ?, ?)
ON CONFLICT (recorded, source_id, key, value)
DO NOTHING;

It seems like my SQL is just saying that I want an index for a table which feels silly…
Is there a better way to do this?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP