Skip to content

Tag: postgresql

Avoid duplicates in postgreSQL

I’m using postgreSQL version 10.3 and I have a table like this: I want to make numerous INSERT and make sure there are no duplicates. So I thought about using INSERT INTO … ON CONFLICT DO NOTHING;. The idea is to insert the record only if the values on the columns first | second | third | fourth |…

“sql: no rows in result set”

I am handling user auth data posted to my Go backend through an HTML form. I am building on some boilerplate to learn Go better. My problem is what the following func returns: func (ctrl …

PostgreSQL json_array_elements with array indexes (keys)

Simple query works fine: But I also want to retrieve array keys somehow so the output would be like: UPD Seems like row_number() is a p̶r̶o̶p̶e̶r̶ solution, but I cannot figure out how to use it further. Lets say i have ‘posts’ table, each post contains an array of related comments in JSON format:…

Finding a single element in postgres json array

I have a table that has a Json typed column and I am trying query that table based of values that are contained in that json column. Here is the relevant DDL: Here is what a roles value would look like: I want to be able to perform a query like this: So I’ve tried this: And it is giving

SQL: Split time interval into intersects of one hour

I am new to SQL, where I am trying to split time intervals into multiple rows of one hour, together with an indicator of how many minutes the interval overlaps each hour. My data: What I would like: What would be the easiest/fastest way to do this? Answer Try something like this: demo Result for sample data