Skip to content
Advertisement

Tag: postgresql

SQL – make a column unique after some timestamp?

Here is my use case. I am using Postgres 13.3 I have a people table under a draft schema that has multiple columns.. email and created_at. The email should have been unique but it was not. If I alter the table to be unique, there were duplicate emails inserted before and I don’t want to lose the data by removing

Go SQL, scanning a row as a slice?

closing note: This question does not ask “how can I find the number of columns returned?” which is len(row.Columns()). It is asking a Go-related question concerning the rows.Scan() function. How can I extract all the columns in a row into a slice or equivalent? For example I would like to extract the data in lastcols as a slice. context: for

How to get data for administrative weeks of a month?

What I want to do is to get the data of each “administrative” week (Monday to Sunday), that is if a month starts a Wednesday,the next week when I would launch the query, I would want the data from Wednesday, Thursday, Friday, Saturday, Sunday of the past week. This would get me data of week 1, and so forth for

Add Column to Result of Postgres Dynamic Query

I have a table that looks like this: I rearranged it to this: Right now, the order of the systems is alphabetical but I created a mapping table in which it orders the priority of the systems Is there a way to adjust the order such that it reflects the priority and is as such: Answer You may find the

Order and limit data based on JSONB array

I have such a PostgreSQL table Now I would like to get all sorted val and have the limitation for each query (for pagination). For example 1st query 2nd query Answer You need to unnest the array, sort the result then apply offset and limit: Instead of limit 5 you can also use the standard compliant fetch first 5 rows

How can I obtain the primary key for a row associated with the minimum value in a subset specified in a group by?

I have been working on some database queries and am running into some issues with trying to obtain a primary key for a row where an aggregated value was obtained. I am using Postgresql v10. Take for example the following table: instructor_schedule_id instructor_name course_name start_date 1 bob databases 2015-01-01 00:00:00.000000 +00:00 2 bob databases 2018-01-01 00:00:00.000000 +00:00 3 bob databases

SUBSELECT (SQL)

I have to tables. The first table (customers) shows data about the customers (id, firstname, lastname). The second table shows data about the orders (timestamp and customer id). So, i wanted to see the last order by a customer in my table “customers” and did a SUBSELECT and it worked. But, there are some customers who never ordered something and

Advertisement