Skip to content

Tag: postgresql

Getting values from 3 tables where two of those are self-joined

Problem Introduction: I’m working on a faker e-banking system as a side project for practicing my SQL skills (which are super bad), and I’m now stuck at a point where I want to pull data from two tables but cannot do that with joins So, basically I have a users table which looks like this: And I h…

Invalid reference to FROM-clause entry for table “mc”

I’m trying to get an item “manufacturer” with an array of contacts and each contact contains an array of translations using this query but I get this error this is the ER diagram dummy data example: I tried to change the structure of the query to solve it but I wasn’t able to fix it. S…

How to write DELETE Statement with Inner Query in PostgreSQL?

The below query works fine in Oracle DB. The same query fails in Postgres DB, but the inner query works fine in Postgres DB. I am getting syntax error for this. Error :- [Code: 0, SQL State: 42601] ERROR: syntax error at or near “(” Position: 13 [Script position: 3109 – 3110] How to fix this…

Postgres: Split column values & transpose

I have a table like this: And I want to convert it to this: I have tried splitting the column based on ; but the product_id count varies based on the category_id. Is there anyway I can achieve this? Answer You can use PostgreSQL’s array manipulation functions: string_to_array does exactly what it says —…