|
79 | 79 | """ |
80 | 80 | CREATE TABLE IF NOT EXISTS {schema}.{tags_table} ( |
81 | 81 | tag text, |
82 | | - type text, |
83 | 82 | main_id bigint REFERENCES {events_table} (id) |
84 | 83 | ) WITH ( |
85 | 84 | autovacuum_enabled = true, |
|
134 | 133 | SELECT |
135 | 134 | t.main_id, |
136 | 135 | qi.ordinality, |
137 | | - t.type, |
138 | 136 | t.tag, |
139 | 137 | qi.tags AS required_tags, |
140 | 138 | qi.types AS allowed_types |
|
188 | 186 | INSERT INTO {schema}.{events_table} (type, data, tags) |
189 | 187 | SELECT i.type, i.data, i.tags |
190 | 188 | FROM input i |
191 | | - RETURNING id, type, tags |
| 189 | + RETURNING id, tags |
192 | 190 | ), |
193 | 191 | expanded_tags AS ( |
194 | 192 | SELECT |
195 | 193 | ins.id AS main_id, |
196 | | - ins.type, |
197 | 194 | tag |
198 | 195 | FROM inserted ins, |
199 | 196 | unnest(ins.tags) AS tag |
200 | 197 | ), |
201 | 198 | tag_insert AS ( |
202 | | - INSERT INTO {schema}.{tags_table} (tag, type, main_id) |
203 | | - SELECT tag, type, main_id |
| 199 | + INSERT INTO {schema}.{tags_table} (tag, main_id) |
| 200 | + SELECT tag, main_id |
204 | 201 | FROM expanded_tags |
205 | 202 | ) |
206 | 203 | SELECT id FROM inserted |
|
236 | 233 | SELECT |
237 | 234 | t.main_id, |
238 | 235 | qi.ordinality, |
239 | | - t.type, |
240 | 236 | t.tag, |
241 | 237 | qi.tags AS required_tags, |
242 | 238 | qi.types AS allowed_types |
|
286 | 282 | INSERT INTO {schema}.{events_table} (type, data, tags) |
287 | 283 | SELECT type, data, tags |
288 | 284 | FROM new_data |
289 | | - RETURNING id, type, tags |
| 285 | + RETURNING id, tags |
290 | 286 | ), |
291 | 287 | expanded_tags AS ( |
292 | | - SELECT ins.id AS main_id, ins.type, tag |
| 288 | + SELECT ins.id AS main_id, tag |
293 | 289 | FROM inserted ins, |
294 | 290 | unnest(ins.tags) AS tag |
295 | 291 | ), |
296 | 292 | tag_insert AS ( |
297 | | - INSERT INTO {schema}.{tags_table} (tag, type, main_id) |
298 | | - SELECT tag, type, main_id |
| 293 | + INSERT INTO {schema}.{tags_table} (tag, main_id) |
| 294 | + SELECT tag, main_id |
299 | 295 | FROM expanded_tags |
300 | 296 | ) |
301 | 297 | SELECT id FROM inserted; |
|
0 commit comments