Skip to content
Advertisement

Tag: postgresql

How to process json data and put it into arrays in postgresql

I have a postgresql table with two columns. name VARCHAR(255) and notes JSON. A sample dataset might look like this: Now I want to do two things. put the list from the json at ‘link_to’ into another column called referrals_to (which must be of array VARCHAR type then). From my example: name notes referrals_to ‘anna’ {‘link_to’: [‘bob’]} [‘bob’] ‘bob’ {‘link_to’:

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 have a transactions

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. Since I don’t have much

Performance impact of view on aggregate function vs result set limiting

The problem Using PostgreSQL 13, I ran into a performance issue selecting the highest id from a view that joins two tables, depending on the select statement I execute. Here’s a sample setup: What I found out I’m executing two statements which result in completely different execution plans and runtimes. The following statement executes in less than 100ms. As far

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 ? Thanks. Answer use

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 — splits a string into an array

Advertisement