-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstatements.go
More file actions
21 lines (17 loc) · 1.91 KB
/
statements.go
File metadata and controls
21 lines (17 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package pg
const (
createNodeStatement = `insert into node (graph_id, kind_ids, properties) values (@graph_id, @kind_ids, @properties) returning (id, kind_ids, properties)::nodeComposite;`
createNodeWithoutIDBatchStatement = `insert into node (graph_id, kind_ids, properties) select $1, unnest($2::text[])::int2[], unnest($3::jsonb[])`
createNodeWithIDBatchStatement = `insert into node (graph_id, id, kind_ids, properties) select $1, unnest($2::int8[]), unnest($3::text[])::int2[], unnest($4::jsonb[])`
deleteNodeWithIDStatement = `delete from node where node.id = any($1)`
createEdgeStatement = `insert into edge (graph_id, start_id, end_id, kind_id, properties) values (@graph_id, @start_id, @end_id, @kind_id, @properties) returning (id, start_id, end_id, kind_id, properties)::edgeComposite;`
// TODO: The query below is not a pure creation statement as it contains an `on conflict` clause to dance around
// Azure post-processing. This was done because Azure post will submit the same creation request hundreds of
// times for the same edge. In PostgreSQL this results in a constraint violation. For now this is best-effort
// until Azure post-processing can be refactored.
createEdgeBatchStatement = `insert into edge as e (graph_id, start_id, end_id, kind_id, properties) select $1, unnest($2::int8[]), unnest($3::int8[]), unnest($4::int2[]), unnest($5::jsonb[]) on conflict (start_id, end_id, kind_id, graph_id) do update set properties = e.properties || excluded.properties;`
deleteEdgeWithIDStatement = `delete from edge as e where e.id = any($1)`
edgePropertySetOnlyStatement = `update edge set properties = properties || $1::jsonb where edge.id = $2`
edgePropertyDeleteOnlyStatement = `update edge set properties = properties - $1::text[] where edge.id = $2`
edgePropertySetAndDeleteStatement = `update edge set properties = properties || $1::jsonb - $2::text[] where edge.id = $3`
)