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

Postgres update Query for Array column

This is so simple query. I need to update Bookings tables’, LinkedBookings column (int array data type) to it’s own Id. Below query didn’t work for me.

update public."Booking" b set "LinkedBookings" = {"Id"}

Above is giving below error,

SQL Error [42601]: ERROR: syntax error at or near "{"

I searching thorough the internet and postgres documentation and couldn’t find any proper simple query. I can understand there is a way to do with writing a Pg Function. Rather than doing such a big thing, isn’t there any simple query for that?

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

>Solution :

Assuming LinkedBookings is an array column and assuming that you want to set it to an array containing only the Id of each row, the correct SQL should be >>

   UPDATE public."Booking" b 
    SET "LinkedBookings" = ARRAY[b."Id"];
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