Hi All,
I have a stored procedure that fails and don't know how to fix it, so I hope to find some help here.
I works on a table called 'locations' that looks like this:
design=# \d locations
Table "public.locations"
Column | Type | Modifiers
---------+----------------------+---------------------
store | character(1) | not null
coord | character varying(8) | not null
room | real | not null
mu | smallint | not null
block | boolean | default false
tags | bit varying(100) | default B'0'::"bit"
details | text |
Indexes:
"locations_pkey" PRIMARY KEY, btree (store, coord)
"store_coord_locations" btree (store, coord)
Check constraints:
"locations_room_check" CHECK (room >= 0.0::double precision)
Foreign-key constraints:
"locations_store_fkey" FOREIGN KEY (store) REFERENCES stores(code)
After some work, it tries to execute the following update:
UPDATE locations SET tags=SUBSTRING(bv,1,r),room=room-$3 WHERE coord=$2 AND store=$1;
and the variables, shown by
raise notice '% % % % % %',bv,r,$3,$2,$1,data.room;
look like this:
NOTICE: 1110110000111000000...0 13 4 BK1B ÷ 4.58
The first value is a binary string, 96 bits long, the tail are just zeroes, so I cut it.
The initial values in the table are:
design=# select * from locations where coord='BK1B' and store=chr(247);
store | coord | room | mu | block | tags | details
-------+-------+------+----+-------+---------------+---------
÷ | BK1B | 4.58 | 1 | f | 1010110000111 | D
(1 row)
And now the error:
ProgrammingError: ERROR: new row for relation "locations" violates check constraint
"location_room_check"
and then the context
If I try to make the update manualy, works flawless (as 4.58-4 >= 0.0).
For now I droped the constrained, but how can I solve it?
Thanks,
Sorin