icingadb/cmd/icingadb-migrate/embed/flapping_query.sql
Alvar Penning f94a65f459
icingadb-migrate: Explicit AS in SELECT
By introducing an explicit "AS" to set output names in the SELECT column
list, there are no issues with reserved names. Unfortunately, this
happened on PostgreSQL in the older version 13 with the reserved name
"name". Adding "AS" mitigates this issue.

Furthermore, I have put each column name in its own line for the SELECT
queries to ease the readability of the query itself and of future diffs.

Fixes #884.
2025-03-05 14:02:01 +01:00

17 lines
601 B
SQL

SELECT
fh.flappinghistory_id,
UNIX_TIMESTAMP(fh.event_time) AS event_time,
fh.event_time_usec,
fh.event_type,
fh.percent_state_change,
fh.low_threshold,
fh.high_threshold,
o.objecttype_id,
o.name1,
COALESCE(o.name2, '') AS name2
FROM icinga_flappinghistory fh USE INDEX (PRIMARY)
INNER JOIN icinga_objects o ON o.object_id=fh.object_id
WHERE fh.flappinghistory_id BETWEEN :fromid AND :toid
AND fh.flappinghistory_id > :checkpoint -- where we were interrupted
ORDER BY fh.flappinghistory_id -- this way we know what has already been migrated from just the last row's ID
LIMIT :bulk