Skip to content
Advertisement

Tag: postgresql

Multiply two existing columns and add result as new column in table

I’ve created a new column ‘jahresbeitrag’ and now I’m trying to multiply two numeric columns to save the values from the query result in this column, but for some reason the query doesn’t work. PgAdmin start executing the query, but it stays at …waiting for the query to complete. Don’t know what I’m doing wrong. Result should be: My query

How to get Postgres to return 0 for empty rows

I have a query which get data summarised between two dates like so: However for dates that do not have any orders, the query returns nothing and I’d like to return 0. I have tried with COALESCE but that doesn’t seem to do the trick? Any suggestions? Answer Please refer to the below script. There is one sample for your

How to leave only distinct rows in the table. Postgresql

I need to delete all duplicate in 40kk of rows. I’ve got table: I’ve tried this query but after 1h of executing I’ve gave up on waiting. Is there any other solution to delete duplicates in more optimazed way? UPD: I need to do it just once cause I didn’t handle the duplicates at the start Answer The database systems

fill in missing dates of date_trunc with last row data

I currently have a query for chart using date_trunc and the result is something like this dates with no value are skipped , however I need it to be like this notice how for 7th and 8th it will use the last available data which is in 6th. Will appreciate any help! Answer Use generate_series to generate a row for

How to append nested key-value to json array in postgresql?

My json values in jsonb column are below: I have nested key – “Images” that has array of strings. How to write query that will add to Images new keys/values (“UploadedBy”:null and “Size”:null) and transform array of string to key-value (“https://face.png” -> “Link”:”https://face.png”) like below: Answer You can use jsonb_set: See fiddle.

Create a new double-field based on the existing string-filed

There is an SQL query forming a table. It is necessary to form another double-number field based on one of the string fields in the table. Values of the original string field (BRLOADSTA0): Values of the resulting double-field (BRLOADSTA9): The request which I’ve create: Full snippet: Thanks in advance even for trying to help πŸ™‚ Answer Could you tell us

Postgres Query Using Join Table

I have 3 tables: users, public_pictures, pictures Import properties: users.id public_pictures.user_id public_pictures.picture_id pictures.id public_pictures is a join table between users and pictures with only those two properties above. Both are foreign keys to their respective table. Given a user.id, I want to get all their public pictures. I tried something like: but this just returns all the user’s images instead

Advertisement