diff options
Diffstat (limited to 'src/sql')
| -rw-r--r-- | src/sql/entityInsert.sql | 6 | ||||
| -rw-r--r-- | src/sql/hostUpsert.sql | 14 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/sql/entityInsert.sql b/src/sql/entityInsert.sql index 8e25810..f518617 100644 --- a/src/sql/entityInsert.sql +++ b/src/sql/entityInsert.sql @@ -1,4 +1,2 @@ -INSERT INTO entities(id, type, value) - VALUES (?, ?, ?) -ON CONFLICT - DO NOTHING +SELECT + entity(?, ?) diff --git a/src/sql/hostUpsert.sql b/src/sql/hostUpsert.sql index 18e8df8..d5ee11d 100644 --- a/src/sql/hostUpsert.sql +++ b/src/sql/hostUpsert.sql @@ -1,7 +1,9 @@ -INSERT INTO entities(id, type, value, detail) - VALUES ($1, 'host', $2, jsonb_build_object('sysname', $3::text, 'release', $4::text, - 'version', $5::text, 'machine', $6::text, 'domainname', $7::text)) -ON CONFLICT ON CONSTRAINT pk_entities +INSERT INTO entities(type, value, detail) + VALUES ('host', $1, jsonb_build_object('sysname', $2::text, 'release', $3::text, + 'version', $4::text, 'machine', $5::text, 'domainname', $6::text)) +ON CONFLICT (md5(value)) DO UPDATE SET - detail = jsonb_build_object('sysname', $3::text, 'release', $4::text, 'version', - $5::text, 'machine', $6::text, 'domainname', $7::text) + detail = jsonb_build_object('sysname', $2::text, 'release', $3::text, 'version', + $4::text, 'machine', $5::text, 'domainname', $6::text) + RETURNING + id |
