postgresql - ERROR: operator is not unique: unknown + unknown -
postgresql - ERROR: operator is not unique: unknown + unknown -
i have postgis database , have compute new values rows in new column. these values should average of values of several columns. query:
insert bdps (da_m) values (avg('da_1'+'da_2'+'da_3'+'da_4'+'da_5'+'da_6'+'da_7'));
in query bdps database, da_m new column , da_1 da_7 existing columns have double precision type.
da_m created using
alter table bdps add together column da_m double precision;
i next error:
error: operator not unique: unknown + unknown line 2: values (avg('da_1'+'da_2'+'da_3'+'da_4'+'da_5'+'da_6'+'da_7... ^ hint: not take best candidate operator. might need add together explicit type casts. ********** error ********** error: operator not unique: unknown + unknown sql state: 42725 hint: not take best candidate operator. might need add together explicit type casts. character: 45
i google , has casts. run postgresql 8.3 , database under postgis 1.5, on windows 7.
you can produce "inlined table" using values , apply average that:
update bdps set da_m = ( select avg(x) (values (da_1), (da_2), (da_3), (da_4), (da_5), (da_6), (da_7)) dt(x) )
that saves messing around coalesce, sign, counting columns hand, etc.
and a_horse_with_no_name (but sql , postgresql skills) mentioned:
don't utilize single quotes column names, table names, or other identifiers. utilize double quotes if need worry upper/lower case issues or unusual characters (or better, rename columns , save grief). use update update existing rows, insert adding new rows. postgresql
Comments
Post a Comment