Reputation: 253
I am creating a temporary table alarm_clusters
within a stored procedure. If I return results via SELECT * FROM alarm_clusters
I get the expected results set:
id |alarm_timestamp |alarm_rule_id |sensor_id |cluster_duration |time_delta |cluster_id |
---|--------------------|--------------|----------|-----------------|-----------|-----------|
1 |2018-01-01 00:00:00 |1 |1 |60 |0 |1 |
2 |2018-01-01 00:02:00 |1 |1 |60 |120 |2 |
3 |2018-01-01 00:02:20 |1 |1 |60 |20 |2 |
whereas if I return only a single column SELECT alarm_timestamp FROM alarm_clusters;
I get the value of that column in the last row repeated:
alarm_timestamp |
--------------------|
2018-01-01 00:02:20 |
2018-01-01 00:02:20 |
2018-01-01 00:02:20 |
I have created a DB Fiddle with two versions of the stored proc.
What have I missed?
Upvotes: 1
Views: 40
Reputation: 1722
You are getting the same time stamp because you are using the declared variable in your select query inside the procedure alarm_timestamp
Check below line in your getAlarmTimestamps procedure.
SELECT alarm_timestamp FROM alarm_clusters;
Ideally you should use different name variable rather than same as table column variable to avoid such kind of small mistakes.
Variable alarm_timestamp has last value which you have set in your cursor, and this value display total times of your rows in alarm_clusters table
I hope this will solve your confusion
Upvotes: 2