Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions quickwit/quickwit-metastore/src/metastore/postgres/metastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1670,15 +1670,15 @@ impl MetastoreService for PostgresqlMetastore {
&self,
_: GetClusterIdentityRequest,
) -> MetastoreResult<GetClusterIdentityResponse> {
// `ON CONFLICT DO NOTHING RETURNING` returns NULL if no insert happens.
// To always get the value, we use this pattern:
let (uuid,) = sqlx::query_as(
r"
WITH insert AS (
INSERT INTO kv (key, value)
VALUES ('cluster_identity', $1)
ON CONFLICT (key) DO NOTHING
)
SELECT value FROM kv where key = 'cluster_identity';
",
INSERT INTO kv (key, value)
VALUES ('cluster_identity', $1)
ON CONFLICT (key) DO UPDATE SET key = EXCLUDED.key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

til about the virtual EXCLUDED table

RETURNING value
",
)
.bind(Uuid::new_v4().hyphenated().to_string())
.fetch_one(&self.connection_pool)
Expand Down