[prev in list] [next in list] [prev in thread] [next in thread]
List: postgresql-sql
Subject: [SQL] PLPGSQL question
From: Sorin Schwimmer <sxn02 () yahoo ! com>
Date: 2006-11-02 23:06:58
Message-ID: 20061102230658.25239.qmail () web56002 ! mail ! re3 ! yahoo ! com
[Download RAW message or body]
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
[Attachment #3 (text/html)]
<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div \
style="font-family:times new roman, new york, times, serif;font-size:12pt"><div>Hi All,<br><br>I have a \
stored procedure that fails and don't know how to fix it, so I hope to find some help here.<br><br>I \
works on a table called 'locations' that looks like this:<br><br>design=# \d \
locations<br> Table \
"public.locations"<br> Column | \
Type | \
Modifiers<br>---------+----------------------+---------------------<br> store | \
character(1) | not null<br> coord | \
character varying(8) | not null<br> room | \
real | \
not null<br> mu | \
smallint | not \
null<br> block | \
boolean | default \
false<br> tags | bit varying(100) | default \
B'0'::"bit"<br> details | \
text \
|<br>Indexes:<br> "locations_pkey" PRIMARY KEY, btree (store, \
coord)<br> "store_coord_locations" btree (store, coord)<br>Check \
constraints:<br> "locations_room_check" CHECK (room >= 0.0::double \
precision)<br>Foreign-key constraints:<br> "locations_store_fkey" FOREIGN KEY (store) \
REFERENCES stores(code)<br><br><br>After some work, it tries to execute the following \
update:<br><br>UPDATE locations SET tags=SUBSTRING(bv,1,r),room=room-$3 WHERE coord=$2 AND \
store=$1;<br><br>and the variables, shown by<br><br>raise notice '% % % % % \
%',bv,r,$3,$2,$1,data.room;<br><br>look like this:<br><br>NOTICE: 1110110000111000000...0 13 4 BK1B ÷ \
4.58<br><br>The first value is a binary string, 96 bits long, the tail are just zeroes, so I cut \
it.<br><br>The initial values in the table are:<br><br>design=# select * from locations where \
coord='BK1B' and store=chr(247);<br> store | coord | room | mu | block | \
tags | \
details<br>-------+-------+------+----+-------+---------------+---------<br> ÷ \
| BK1B | 4.58 | 1 | f | 1010110000111 | D<br>(1 row)<br><br>And now \
the error:<br><br>ProgrammingError: ERROR: new row for relation "locations" violates check \
constraint<br>"location_room_check"<br>and then the context<br><br><br>If I try to make the update \
manualy, works flawless (as 4.58-4 >= 0.0).<br><br>For now I droped the constrained, but how can I \
solve it?<br><br>Thanks,<br>Sorin<br></div></div><br></body></html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic