Skip to content
Advertisement

Tag: postgresql

PostgreSQL: Using CTE with IN

Learning CTE right now, the following query is super basic and it doesn’t really have any useful value but I don’t understand why it doesn’t work The error I’m getting is “ERROR: column “cte_actors” does not exist” Currently using postgres 14 and DBeaver Answer You need to SELECT from the CTE:

Grouped aggregate counts for each date in a series of dates

I am trying to get grouped task counts by state over a series of dates using the following tables: There isn’t a consistent daily “state” record for each task because task_logs only has entries for when a task changes state. This means I have to get the last “state change” log for each task prior to a specified date. I’ve

Continuous subset and ranking using sql

I have a dataset like below: Now, I need the output as below: For this purpose, I wrote a query but it is not giving me the desired sequence. My query is as below: It generates the output as below: But in the rank section I need something as below: So, what exactly am I doing wrong here? Here are

Postgres: Searching all sub-arrays of an array

I have a Postgres table with a json column, named raw_data, that is structured like this: [{“id”:1234, “name”:”John Doe”, “purchases”:12}, {“id”:1234, “name”:”Jane Doe”, “purchases”:11}] The number of sub-arrays can differ. It may be 1 or 20 or any number. I want to perform a query where I can return the entire table row if, say, ‘John Doe’ occurs in the

PostgreSQL get all records with most recent date

I have this query that will run on very large data sets and it is too slow. table A looks something like this pk columnA columnB columnC 1 5/6/2022 1234 1 2 5/6/2022 1234 2 3 5/5/2022 0000 3 4 5/3/2022 0000 4 There are about 1000 distinct entries in columnB and many orders of magnitude more in the table.

Sql / Finding Min Max values for each elements of another column

Learning sql, as per title trying to print min and max values of a given column (sal) for each values in another (nodept). Using this query so far: Which works but only returns absolute min max and not min max for every entry in nodept. Documentation says it should be a simple matter of adding GROUP BY to the query

Remove schema name from DBeaver’s query

I am new to DBeaver and I am using it for the postgres client. I was using Navicat before and in navicat the query simply used to run without schema name as SELECT * FROM TABLE_NAME . However, I am having issues with the Navicat and I recently switched on DBeaver(22.0.4 mac). With DBeaver, I cannot execute query without schema

Advertisement