-
Hi, thank you for making this cool piece of software. I'm trying make alert when my device skips value update. This sql code i'm using. SELECT
mac,
mac::TEXT || ' Older than 30 minutes' AS status
FROM node
GROUP BY mac
HAVING MAX(created_at) IS NOT NULL AND NOW() - INTERVAL '30 minutes' > MAX(created_at) Can I somehow show alert component if this is true? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 13 replies
-
Hello and welcome to SQLPage ! If I understand well, you have a table that looks something like this: CREATE TABLE node (
mac macaddr,
-- other fields
created_at timestamp
); and you want to create a web page that will contain one alert message for each value of mac that does not have an entry with a created_at that is before 30 minutes ago. Is that right ? Here is how you could do this with sqlpage: SELECT
'alert' AS component,
'Missing value update' AS title,
mac::TEXT || ' older than 30 minutes' AS description,
'alert-circle' AS icon,
'red' AS color
FROM
node
GROUP BY
mac
HAVING
MAX(created_at) < NOW() - INTERVAL '30 minutes' does this answer your question ? I made a small SQLite example you can fiddle with online on replit: |
Beta Was this translation helpful? Give feedback.
-
When I try your code on db it works. But for some reason nothing is showing on sqlpage. |
Beta Was this translation helpful? Give feedback.
-
You weren't kidding when you said it will be long log. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure where to put this sql? |
Beta Was this translation helpful? Give feedback.
-
Yea it's not working. error returned from database: column "mac" does not exist probably because there is not from table name "node". Sorry I am a noob. |
Beta Was this translation helpful? Give feedback.
-
Yes you are right. This is postgres db. I changed timestamp for created_at after i created db. Now I am not sure how and what command I used. I need to find that. As you can see in SQLPage time is 2023-12-01T13:09:01.285074+00:00 and if I run the same sql on db it's
|
Beta Was this translation helpful? Give feedback.
-
I use DBeaver as client. You are right, created_at is timestamp without time zone. And if I "SET TIME ZONE 'Europe/Sarajevo' it shows alert. Wooohooo. Now I need to change timestamp for created_at in db. Now is there option to show missing updates for all devices in one alert under description? Now if there are multiple devises they all get their own alert. Thanks for all your help. You rock. |
Beta Was this translation helpful? Give feedback.
-
Thanks man. There was small syntax issue that I fix with gpt. ;) SELECT
'alert' AS component,
'Missing value update' AS title,
string_agg(mac::text, ', ') AS description,
'alert-circle' AS icon,
'red' AS color
FROM (
SELECT mac, MAX(created_at) AS max_created_at
FROM node
GROUP BY mac
HAVING MAX(created_at) < NOW() - INTERVAL '2 minutes'
) AS subquery; Anyway thanks for all your help. Have a great weekend. |
Beta Was this translation helpful? Give feedback.
-
Hi again. I'm having problem with this query. The problem is that 'Missing value update' is always shown on page even when no mac shown in description as they are not exceeded 2 minutes interval. I would like to hide alert when no value is beyond that interval. ChatGPT didn't help me with this problem :) |
Beta Was this translation helpful? Give feedback.
You can add a
HAVING
clause to the outer query to prevent it from returning a row if you don't have values:I'm happy to answer your questions here, but when you have more general questions that are related to SQL in general and are not specific to SQLPage, you may receive better answers by asking on stackoverflow. When asking there, you can mention in the …