|
21 | 21 | -- Example generated SQL for upserting 2 timeseries (constructed in getUpsertStatement) |
22 | 22 | WITH input_rows AS (SELECT * |
23 | 23 | FROM (SELECT * |
24 | | - FROM (VALUES ((NULL::time_series).link_href, (NULL::time_series).link_rel, |
25 | | - (NULL::time_series).link_type, (NULL::time_series).link_hreflang, |
26 | | - (NULL::time_series).link_title, (NULL::time_series).level, |
27 | | - (NULL::time_series).period, (NULL::time_series).version, |
28 | | - (NULL::time_series).type, (NULL::time_series).title, |
29 | | - (NULL::time_series).summary, (NULL::time_series).keywords, |
30 | | - (NULL::time_series).keywords_vocabulary, (NULL::time_series).license, |
31 | | - (NULL::time_series).conventions, (NULL::time_series).naming_authority, |
32 | | - (NULL::time_series).creator_type, (NULL::time_series).creator_name, |
33 | | - (NULL::time_series).creator_email, (NULL::time_series).creator_url, |
34 | | - (NULL::time_series).institution, (NULL::time_series).project, |
35 | | - (NULL::time_series).source, (NULL::time_series).platform, |
36 | | - (NULL::time_series).platform_vocabulary, (NULL::time_series).platform_name, |
37 | | - (NULL::time_series).standard_name, (NULL::time_series).unit, |
38 | | - (NULL::time_series).function, (NULL::time_series).instrument, |
39 | | - (NULL::time_series).instrument_vocabulary, (NULL::time_series).parameter_name, |
40 | | - (NULL::time_series).timeseries_id, |
41 | | - (NULL::time_series).quality_code_vocabulary), -- header column to get correct column types |
42 | | - ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, |
43 | | - $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34), |
44 | | - ($35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, |
45 | | - $51, $52, $53, $54, $55, $56, $57, $58, $59, $60, $61, $62, $63, $64, $65, $66, |
46 | | - $67, $68) -- actual values |
47 | | - ) t (link_href, link_rel, link_type, link_hreflang, link_title, level, period, version, |
48 | | - type, title, summary, keywords, keywords_vocabulary, license, conventions, |
49 | | - naming_authority, creator_type, creator_name, creator_email, creator_url, |
50 | | - institution, project, source, platform, platform_vocabulary, platform_name, |
51 | | - standard_name, unit, function, instrument, instrument_vocabulary, parameter_name, |
52 | | - timeseries_id, quality_code_vocabulary) |
53 | | - OFFSET 1) t |
| 24 | + FROM (VALUES ((NULL::time_series).link_href, (NULL::time_series).link_rel, |
| 25 | + (NULL::time_series).link_type, (NULL::time_series).link_hreflang, |
| 26 | + (NULL::time_series).link_title, (NULL::time_series).level, |
| 27 | + (NULL::time_series).period, (NULL::time_series).version, |
| 28 | + (NULL::time_series).type, (NULL::time_series).title, |
| 29 | + (NULL::time_series).summary, (NULL::time_series).keywords, |
| 30 | + (NULL::time_series).keywords_vocabulary, (NULL::time_series).license, |
| 31 | + (NULL::time_series).conventions, (NULL::time_series).naming_authority, |
| 32 | + (NULL::time_series).creator_type, (NULL::time_series).creator_name, |
| 33 | + (NULL::time_series).creator_email, (NULL::time_series).creator_url, |
| 34 | + (NULL::time_series).institution, (NULL::time_series).project, |
| 35 | + (NULL::time_series).source, (NULL::time_series).platform, |
| 36 | + (NULL::time_series).platform_vocabulary, (NULL::time_series).platform_name, |
| 37 | + (NULL::time_series).standard_name, (NULL::time_series).unit, |
| 38 | + (NULL::time_series).function, (NULL::time_series).instrument, |
| 39 | + (NULL::time_series).instrument_vocabulary, (NULL::time_series).parameter_name, |
| 40 | + (NULL::time_series).timeseries_id, |
| 41 | + (NULL::time_series).quality_code_vocabulary), -- header column to get correct column types |
| 42 | + ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, |
| 43 | + $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34), |
| 44 | + ($35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, |
| 45 | + $51, $52, $53, $54, $55, $56, $57, $58, $59, $60, $61, $62, $63, $64, $65, $66, |
| 46 | + $67, $68) -- actual values |
| 47 | + ) t (link_href, link_rel, link_type, link_hreflang, link_title, level, period, version, |
| 48 | + type, title, summary, keywords, keywords_vocabulary, license, conventions, |
| 49 | + naming_authority, creator_type, creator_name, creator_email, creator_url, |
| 50 | + institution, project, source, platform, platform_vocabulary, platform_name, |
| 51 | + standard_name, unit, function, instrument, instrument_vocabulary, parameter_name, |
| 52 | + timeseries_id, quality_code_vocabulary) |
| 53 | + OFFSET 1) t |
54 | 54 | ORDER BY naming_authority, platform, standard_name, level, function, period, |
55 | | - instrument -- ORDER BY for consistent order to avoid deadlocks |
| 55 | + instrument -- ORDER BY for consistent order to avoid deadlocks |
56 | 56 | ) |
57 | 57 | , ins AS ( |
58 | 58 | INSERT INTO time_series (link_href, link_rel, link_type, link_hreflang, link_title, level, period, version, type, |
59 | | - title, summary, keywords, keywords_vocabulary, license, conventions, naming_authority, |
60 | | - creator_type, creator_name, creator_email, creator_url, institution, project, source, |
61 | | - platform, platform_vocabulary, platform_name, standard_name, unit, function, instrument, |
62 | | - instrument_vocabulary, parameter_name, timeseries_id, quality_code_vocabulary) |
| 59 | + title, summary, keywords, keywords_vocabulary, license, conventions, naming_authority, |
| 60 | + creator_type, creator_name, creator_email, creator_url, institution, project, source, |
| 61 | + platform, platform_vocabulary, platform_name, standard_name, unit, function, instrument, |
| 62 | + instrument_vocabulary, parameter_name, timeseries_id, quality_code_vocabulary) |
63 | 63 | SELECT * FROM input_rows |
64 | 64 | ON CONFLICT ON CONSTRAINT unique_main |
65 | 65 | DO UPDATE SET link_rel = EXCLUDED.link_rel,keywords = EXCLUDED.keywords,conventions = EXCLUDED.conventions,platform_name = EXCLUDED.platform_name,quality_code_vocabulary = EXCLUDED.quality_code_vocabulary,summary = EXCLUDED.summary,project = EXCLUDED.project,source = EXCLUDED.source,title = EXCLUDED.title,platform_vocabulary = EXCLUDED.platform_vocabulary,license = EXCLUDED.license,creator_type = EXCLUDED.creator_type,version = EXCLUDED.version,instrument_vocabulary = EXCLUDED.instrument_vocabulary,link_type = EXCLUDED.link_type,link_hreflang = EXCLUDED.link_hreflang,type = EXCLUDED.type,keywords_vocabulary = EXCLUDED.keywords_vocabulary,timeseries_id = EXCLUDED.timeseries_id,link_href = EXCLUDED.link_href,link_title = EXCLUDED.link_title,creator_url = EXCLUDED.creator_url,parameter_name = EXCLUDED.parameter_name,creator_name = EXCLUDED.creator_name,creator_email = EXCLUDED.creator_email,institution = EXCLUDED.institution,unit = EXCLUDED.unit -- do update of fields not in unique constraint |
66 | 66 | WHERE time_series.link_href IS DISTINCT FROM EXCLUDED.link_href OR |
67 | | - time_series.link_hreflang IS DISTINCT FROM EXCLUDED.link_hreflang OR |
68 | | - time_series.creator_email IS DISTINCT FROM EXCLUDED.creator_email OR |
69 | | - time_series.type IS DISTINCT FROM EXCLUDED.type OR |
70 | | - time_series.keywords IS DISTINCT FROM EXCLUDED.keywords OR |
71 | | - time_series.instrument_vocabulary IS DISTINCT FROM EXCLUDED.instrument_vocabulary OR |
72 | | - time_series.quality_code_vocabulary IS DISTINCT FROM EXCLUDED.quality_code_vocabulary OR |
73 | | - time_series.summary IS DISTINCT FROM EXCLUDED.summary OR |
74 | | - time_series.creator_name IS DISTINCT FROM EXCLUDED.creator_name OR |
75 | | - time_series.project IS DISTINCT FROM EXCLUDED.project OR |
76 | | - time_series.timeseries_id IS DISTINCT FROM EXCLUDED.timeseries_id OR |
77 | | - time_series.link_type IS DISTINCT FROM EXCLUDED.link_type OR |
78 | | - time_series.conventions IS DISTINCT FROM EXCLUDED.conventions OR |
79 | | - time_series.creator_url IS DISTINCT FROM EXCLUDED.creator_url OR |
80 | | - time_series.platform_vocabulary IS DISTINCT FROM EXCLUDED.platform_vocabulary OR |
81 | | - time_series.parameter_name IS DISTINCT FROM EXCLUDED.parameter_name OR |
82 | | - time_series.link_rel IS DISTINCT FROM EXCLUDED.link_rel OR |
83 | | - time_series.creator_type IS DISTINCT FROM EXCLUDED.creator_type OR |
84 | | - time_series.source IS DISTINCT FROM EXCLUDED.source OR |
85 | | - time_series.platform_name IS DISTINCT FROM EXCLUDED.platform_name OR |
86 | | - time_series.link_title IS DISTINCT FROM EXCLUDED.link_title OR |
87 | | - time_series.version IS DISTINCT FROM EXCLUDED.version OR |
88 | | - time_series.license IS DISTINCT FROM EXCLUDED.license OR |
89 | | - time_series.title IS DISTINCT FROM EXCLUDED.title OR |
90 | | - time_series.institution IS DISTINCT FROM EXCLUDED.institution OR |
91 | | - time_series.keywords_vocabulary IS DISTINCT FROM EXCLUDED.keywords_vocabulary OR |
92 | | - time_series.unit IS DISTINCT FROM EXCLUDED.unit -- only if at least one value is actually different, to avoid table churn |
| 67 | + time_series.link_hreflang IS DISTINCT FROM EXCLUDED.link_hreflang OR |
| 68 | + time_series.creator_email IS DISTINCT FROM EXCLUDED.creator_email OR |
| 69 | + time_series.type IS DISTINCT FROM EXCLUDED.type OR |
| 70 | + time_series.keywords IS DISTINCT FROM EXCLUDED.keywords OR |
| 71 | + time_series.instrument_vocabulary IS DISTINCT FROM EXCLUDED.instrument_vocabulary OR |
| 72 | + time_series.quality_code_vocabulary IS DISTINCT FROM EXCLUDED.quality_code_vocabulary OR |
| 73 | + time_series.summary IS DISTINCT FROM EXCLUDED.summary OR |
| 74 | + time_series.creator_name IS DISTINCT FROM EXCLUDED.creator_name OR |
| 75 | + time_series.project IS DISTINCT FROM EXCLUDED.project OR |
| 76 | + time_series.timeseries_id IS DISTINCT FROM EXCLUDED.timeseries_id OR |
| 77 | + time_series.link_type IS DISTINCT FROM EXCLUDED.link_type OR |
| 78 | + time_series.conventions IS DISTINCT FROM EXCLUDED.conventions OR |
| 79 | + time_series.creator_url IS DISTINCT FROM EXCLUDED.creator_url OR |
| 80 | + time_series.platform_vocabulary IS DISTINCT FROM EXCLUDED.platform_vocabulary OR |
| 81 | + time_series.parameter_name IS DISTINCT FROM EXCLUDED.parameter_name OR |
| 82 | + time_series.link_rel IS DISTINCT FROM EXCLUDED.link_rel OR |
| 83 | + time_series.creator_type IS DISTINCT FROM EXCLUDED.creator_type OR |
| 84 | + time_series.source IS DISTINCT FROM EXCLUDED.source OR |
| 85 | + time_series.platform_name IS DISTINCT FROM EXCLUDED.platform_name OR |
| 86 | + time_series.link_title IS DISTINCT FROM EXCLUDED.link_title OR |
| 87 | + time_series.version IS DISTINCT FROM EXCLUDED.version OR |
| 88 | + time_series.license IS DISTINCT FROM EXCLUDED.license OR |
| 89 | + time_series.title IS DISTINCT FROM EXCLUDED.title OR |
| 90 | + time_series.institution IS DISTINCT FROM EXCLUDED.institution OR |
| 91 | + time_series.keywords_vocabulary IS DISTINCT FROM EXCLUDED.keywords_vocabulary OR |
| 92 | + time_series.unit IS DISTINCT FROM EXCLUDED.unit -- only if at least one value is actually different, to avoid table churn |
93 | 93 | RETURNING id, naming_authority,platform,standard_name,level,function,period,instrument -- RETURNING only gives back rows that were actually inserted or modified |
94 | 94 | ) |
95 | 95 | SELECT id, |
|
0 commit comments