Possible Duplicate:
convert MySQL SET data type to Postgres
I have postgresql 8.4.
I am trying to build up a query without success. I would like to insert elements into an array if they are not exists in the conserning row.
TABLE “test”:
+------------------+------------------+
| id | varchar(20) |
| timestp | timestamp |
| place | varchar(20) |
| myarray[][] | varchar[14][254] |
+------------------+------------------+
+---------+---------------------+-----------+----------------+
| xyz | 2010-01-01 10:10:10 | nowhere | "{abc,qwert}" |
+---------+---------------------+-----------+----------------+
So I would like to add “{fgh,gfdsa}” to myarray WHERE (id=’xyz’ AND timestp=”2010-01-01 10:10:10″ AND place=’nowhere’) IF it is not already in myarray
I tried something like this>
UPDATE test
SET myarray = array_append(wascon2,'{fgh,gfdsa}')
WHERE (id='xyz' AND timestp="2010-01-01 10:10:10" AND place='nowhere'
AND NOT EXISTS 1 FROM test WHERE (myarray='{fgh,gfdsa}')));
This doesnt work, it will append the array every time when I call it.
+---+---------------------------+-------------------------------------------+
|xyz|2010-01-01 10:10:10|nowhere|{"{abc,qwert}","{fgh,gfdsa}","{fgh,gfdsa}"}|
+---+---------------------------+-------------------------------------------+
If think I should use >
myarray = ANY ('{fgh,gfds}'::varchar[])
somehow but I cant find out how..
The best wolud be a plpgsql function for me.
1 Answer