pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sorin Schwimmer <sxn02@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: PLPGSQL question
Date: Thu, 2 Nov 2006 15:06:58 -0800 (PST)
Message-ID: <20061102230658.25239.qmail@web56002.mail.re3.yahoo.com> (raw)

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





view thread (14+ messages)

Message-ID: <20061102230658.25239.qmail@web56002.mail.re3.yahoo.com>
Permalink:  ../20061102230658.25239.qmail@web56002.mail.re3.yahoo.com/
Also on:    postgresql.org/message-id/20061102230658.25239.qmail@web56002.mail.re3.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sxn02@yahoo.com
  Subject: Re: PLPGSQL question
  In-Reply-To: <20061102230658.25239.qmail@web56002.mail.re3.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox