John
John

Reputation: 127

How can i delete a specific name from my postgres array

Hello everyone I just started on working with postgreSQL and i was wondering if there is a simple solution to delete a single value from an array. In the screenshot im trying to delete a single name from my array.

my PostgreSQL version: "PostgreSQL 12.4, compiled by Visual C++ build 1914, 64-bit"

here is what im trying to do

Upvotes: 1

Views: 912

Answers (1)

user330315
user330315

Reputation:

DELETE removes an entire row from your table.

You want to change the content of one column of an existing row in the table - for that you need to use UPDATE.

To remove a value from an array you the array_remove() function:

update test
   set name = array_remove(name, 'Jan')
where 'Jan' = any(name)

The where clause makes sure that only rows are updated that actually contain the value Jan in the array.

Upvotes: 2

Related Questions