Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 before but don’t want to change the orignal data from "gia_su_pro" table

Here is what i did:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • 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', ',');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading