This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.sql
78 lines (74 loc) · 1.67 KB
/
query.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- name: UpsertProject :exec
INSERT INTO projects(
external_primary_identifier,
external_identifiers,
name,
description,
founding_date,
dissolution_date,
acronym,
eu_grant_call,
eu_funding_programme,
created_at,
updated_at
)
VALUES(
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8,
$9,
current_timestamp,
current_timestamp
) ON CONFLICT (external_primary_identifier) DO
UPDATE
SET external_identifiers = excluded.external_identifiers,
name = excluded.name,
description = excluded.description,
founding_date = excluded.founding_date,
dissolution_date = excluded.dissolution_date,
acronym = excluded.acronym,
eu_grant_call = excluded.eu_grant_call,
eu_funding_programme = excluded.eu_funding_programme,
created_at = projects.created_at,
updated_at = current_timestamp;
-- name: GetProject :one
SELECT pk,
external_primary_identifier,
external_identifiers,
name,
description,
founding_date,
dissolution_date,
acronym,
eu_grant_call,
eu_funding_programme,
created_at,
updated_at
FROM projects
WHERE external_primary_identifier = $1
LIMIT 1;
-- name: SuggestProjects :many
SELECT pk,
external_primary_identifier,
external_identifiers,
name,
description,
founding_date,
dissolution_date,
acronym,
eu_grant_call,
eu_funding_programme,
created_at,
updated_at
FROM projects
WHERE ts @@ to_tsquery('usimple', $1)
LIMIT 20;
-- name: DeleteProject :one
DELETE FROM projects
WHERE external_primary_identifier = $1
RETURNING pk;