Postgres - Cast to boolean
I'm trying to update a Postgres database to set a boolean but I'm getting the following error
No operator matches the given name and argument type(s). You may need to add explicit type casts.
开发者_JAVA百科I've cut down the table description to show it's structure.
Column | Type | Modifiers
--------------------+-----------------------------+-----------
archived | boolean |
The column in the db is currently empty so I have no others to use as a comparison.
I've tried the following:
UPDATE table_name SET archived=TRUE WHERE id=52;
UPDATE table_name SET archived='t' WHERE id=52;
UPDATE table_name SET archived='1' WHERE id=52;
UPDATE table_name SET archived='t'::boolean WHERE id=52;
Neither of these have worked.
How do I cast my UPDATE to a boolean?
UPDATE: full error message
play_mercury=# UPDATE opportunities SET archived=TRUE WHERE id=(52,55,35,17,36,22,7,2,27,15,10,9,13,5,34,40,30,23,21,8,26,18,3,42,25,20,41,28,19,14,39,44,16,24,4,33,54,47,29,38,64);
ERROR: operator does not exist: bigint = record
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.
The problem is in the WHERE id=(52,55,...)
Use: WHERE id IN (52,55,...)
Your WHERE
condition is wrong. You need to use IN instead of =
UPDATE opportunities
SET archived=TRUE
WHERE id IN (52,55,35,17,36,22,7,2,27,15,10,9,13,5,34,40,30,23,21,8,26,18,3,42,25,20,41,28,19,14,39,44,16,24,4,33,54,47,29,38,64);
How are you trying this? Via plsql? According to the docs those should be valid and this also works for me:
tmp=# create table bar (a boolean, b int);
CREATE TABLE
tmp=# insert into bar values (TRUE, 1);
INSERT 0 1
tmp=# update bar set a=false where b=1;
UPDATE 1
tmp=# \d bar
Table "public.bar"
Column | Type | Modifiers
--------+---------+-----------
a | boolean |
b | integer |
精彩评论