PLPGSQL question

From: Sorin Schwimmer <sxn02(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: PLPGSQL question
Date: 2006-11-02 23:06:58
Message-ID: 20061102230658.25239.qmail@web56002.mail.re3.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Hanson 2006-11-02 23:16:48 Re: Determining correct table order for insert or drop statements to satisfy foreign keys
Previous Message Aaron Bono 2006-11-02 22:58:05 Re: Determining correct table order for insert or drop statements to satisfy foreign keys