Using UPDATE keyword to update a CTE

I currently using PostgreSQL through DBeaver In my "gia_su_pro" table, at "course_id" field, currently there is some cell contains more than one ID for the same course and separated by a paragraph separator ΒΆ (Pilcrow symble). I want to separate the course ID and create a new record for it with the same value as… Read More Using UPDATE keyword to update a CTE

Postgresql – How to SELECT using a json aggregate function that takes two columns as key: value pair?

Supposing I have something like Name username Mike BestMike99 Someone DaBest What query do I need to run in order to SELECT/return a json like json_agg {Mike: BestMike99, Someone: Dabest} >Solution : Having create table users ("Name" varchar, username varchar); It would be select array_to_json(array_agg( concat(‘{"’,"Name",’": "’,username,’"}’)::json)) from users; Working sample here

How to specify native table fields and a foreign table field during an insert?

Suppose the following: create table member ( id serial primary key, member_name varchar(55), role_ids bigint[] not null ); create table role ( id serial primary key, role_name varchar(55) unique ); insert into role values (1, ‘admin’), (2, ‘common’); I can create an admin member like this: insert into member (role_ids) select ARRAY[id] as role_id from… Read More How to specify native table fields and a foreign table field during an insert?

Use of NATURAL JOIN

According by the task I’m doing I need to change INNER JOIN to NATURAL JOIN and get the same result as this result of inner join I got that result with this query: SELECT person_order.order_date, person.name || ‘ (‘ || ‘age:’ || person.age || ‘)’ AS person_information FROM person_order INNER JOIN person ON person_order.person_id =… Read More Use of NATURAL JOIN