Search code examples
sqlpostgresqlplpgsql

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?


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"];