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 before but don’t want to change the orignal data from "gia_su_pro" table
Here is what i did:
- I change the Pilcrow symble to comma so i can seperate it but get stuck at the changing step.
- I create a CTE named "gia_su_pro_virtual" that contained all the data from "gia_su_pro" table then update to change Pilcrow symble into comma.
- The result return error relation "gia_su_pro_virtual" does not exist
I check at the PostgreSQL document and they said i can use CTE with UPDATE keyword so i don’t know what i did wrong.
Please help me separate the course ID and create a new record for it with the same value as before but don’t change the orignal data from "gia_su_pro" table
Here is my code:
with gia_su_pro_virtual as (
select *
from gia_su_pro gsp)
update gia_su_pro_virtual gsv
set gsv.coure_id = REPLACE(gsv.course_id, E'\u00B6', ',')
Here is the error result:
(https://i.stack.imgur.com/FnUhG.png)
And here is the document i read from postgre website
(https://i.stack.imgur.com/8EzBO.png)
>Solution :
Postgres does not support updatable common table expressions (although some other databases, such as SQL Server, do in fact support them). In this particular case, you should just do an update directly against the table:
UPDATE gia_su_pro_virtual
SET coure_id = REPLACE(course_id, E'\u00B6', ',');