We have a monitoring system that posts data to our postgres database in this format: Our goal is to calculate the time between wa-event-triggered events and wa-event-recovered events, if i have data that looks like this, my query below works just fine. This gives me this table which is great! However the data…
Tag: postgresql
Get the number of the weekday from each date in a date list
DB-Fiddle Expected Results: I want go get the number of the weekday for each date in the table dates. Therefore, I tried to go with the solution from this question but could not make it work: How do I need to modify the query to get the expected result? Answer Get rid of the date keyword it is only needed
Deserialize Postgres ARRAY [@tags] to List with Dapper?
I’m using Dapper with Npsql (Postgres). I’m saving a serialized list of strings to one column called tags: which is resulting in {{first,second}} in the database. My question is how to read it back to the model? Do I need some special SQL, or can I use SELECT id, text, tags FROM account;? How can …
PostgreSQL limit by variable value in a CTE
I am trying to fetch some results from the database using two SQL select queries, I am using CTE, but since I have millions of rows I need to limit the results, I want to limit results to 20, what I tried is: Aggregate functions don’t seem to work on limit, moreover, even if they do, I would have a
Displaying Multiple Rows of Data from Two Tables with a One to Many Relationship
I have two tables. Tracks and metadata. Tracks can have multiple metadata attributes, but metadata can only be attached to a single track. The metadata table has a foreign key for a track ID, but the tracks table has no foreign keys for metadata. I am trying to find the best way to get this result: Essentiall…
How to return deleted rows using jdbi?
How do I return the deleted rows using jdbi? For example, I’d like to do something like this: Answer Postgresql has a returning keyword… https://dbfiddle.uk/?rdbms=postgres_13&fiddle=25d284309745e40c8ea29945481d1aa2 You can then execute that query in the same way as you would a normal SELECT s…
How to provide list to epgsql sql where in clause (Erlang)
I can’t find the right syntax for providing a list of values to epgsql:equery function to use in the sql where in clause. I googled and tried several variants, all of them failed. Some of my tries are …
SQL add a column with COUNT(*) to my query
I need to add a column with the content of this query : to this query : I tried adding a LEFT JOIN like that: with this line in my WHERE statement : and this line in my SELECT : but I get an error : I don’t understand how I could perform this action properly Answer To count something,
Query to get the Average of ONLY the first occurrences
I have 2 tables like these: Table Info Table A I need to take the first occurrence (occurrency_date ordered asc) of each Info and subtract from when the Info was created (created_date), after that take the average between them Something like this: I made many attempts but none were successful, how could I get…
SQL some selections into one (or get two colums from one)
I use PostgreSql, I have two tables (for example) Let table1 will contain stores, there are 2 types ‘candy store’ and ‘dental store’. Each row contains information about a customer’s purchase in a …