I'm new to sql and I'm trying to append a string to a text array column only if the array does not already contain the string :
UPDATE users
SET sharedfolders = array_append(sharedfolders, '/test2/test3/aaaa')
WHERE companyid = 2
AND scope = 2
AND id = 3
AND NOT ('/test2/test3/aaaa' = ANY (sharedfolders))
Here is my table :
CREATE TABLE users (
id SERIAL PRIMARY KEY,
companyid INT REFERENCES companies (id) ON UPDATE CASCADE ON DELETE CASCADE,
email VARCHAR UNIQUE,
lastname VARCHAR(50),
firstname VARCHAR(50),
password VARCHAR,
scope SMALLINT,
sharedfolders TEXT[]
);
This query does not work even if I have an user with scope = 2, id = 3, company = 2 and an empty array.
Is it not working because the array is not defined or am I missing something ?
PS: if I remove the AND NOT ('/test2/test3/aaaa' = ANY (sharedfolders)) it's obviously working.