小编Luk*_*don的帖子

Postgres 中的高效键值存储

我想使用 Postgres(CloudSQL 中的 11)作为高效的键值存储。我有大约 200GB 的字典(平均大小为 10kB,结构可以不同并且可以嵌套)。我正在考虑利用改进的哈希索引。这是架构:

\n\n
        CREATE EXTENSION IF NOT EXISTS "uuid-ossp";\n\n        CREATE TABLE IF NOT EXISTS key_val (\n            id uuid DEFAULT uuid_generate_v4(),\n            value jsonb,\n            EXCLUDE using hash (id with =)\n        );\n\n        CREATE INDEX IF NOT EXISTS idx_key_val ON key_val USING hash (id);\n
Run Code Online (Sandbox Code Playgroud)\n\n

获取、更新和插入非常简单,但我不知道如何实现高效的更新插入。

\n\n
INSERT INTO key_val VALUES ($1, $2) ON CONFLICT ON CONSTRAINT key_val_id_excl DO UPDATE SET value = ($2)\n
Run Code Online (Sandbox Code Playgroud)\n\n

结果是WrongObjectTypeError ON CONFLICT DO UPDATE not supported with exclusion constraints

\n\n

可能的解决方案:

\n\n …

postgresql upsert json hashing google-cloud-sql

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

google-cloud-sql ×1

hashing ×1

json ×1

postgresql ×1

upsert ×1