Sender: owner-postgres95@postgres.Berkeley.EDU
X-Return-Path: andrew_yu
Received: from gaudi.diatel.upm.es (gaudi.diatel.upm.es [138.100.49.10]) by nobozo.CS.Berkeley.EDU (8.6.10/8.6.3) with SMTP id JAA28122 for <postgres95@postgres.berkeley.edu>; Thu, 2 Nov 1995 09:51:26 -0800
Received: by gaudi.diatel.upm.es (4.1/SMI-4.1) Thu, 2 Nov 95 18:49:59 +0100
X400-Received: by mta diatel.upm in /PRMD=/ADMD=/C=/; Relayed; Thu,  2 Nov 1995 18:49:48 UTC+0100
X400-Received: by /PRMD=iris/ADMD=mensatex/C=es/; Relayed; Thu,  2 Nov 1995 18:49:48 UTC+0100
Date: Thu,  2 Nov 1995 18:49:48 UTC+0100
X400-Originator: jmrueda@diatel.upm.es
X400-Recipients: non-disclosure:;
X400-Content-Type: P2-1984 (2)
X400-Mts-Identifier: [/PRMD=iris/ADMD=mensatex/C=es/;951102184948]
Content-Identifier: 849
From: Javier Martin Rueda <jmrueda@diatel.upm.es>
To: postgres95@postgres.Berkeley.EDU
Message-Id: <849*/S=jmrueda/OU=diatel/O=upm/PRMD=iris/ADMD=mensatex/C=es/@MHS>
Subject: Bug? report (mixing integers and reals)
Mime-Version: 1.0 (Generated by Ean X.400 to MIME gateway)
Resent-To: postgres95-redist
Resent-Date: Thu, 02 Nov 95 09:51:31 -0800
Resent-From: pglite
Resent-XMts: smtp

============================================================================
                        POSTGRES95 BUG REPORT TEMPLATE
============================================================================


Your name		:	Javier Martin Rueda
Your email address	: jmrueda@diatel.upm.es


System Configuration
---------------------
  Architecture (example: DEC Alpha AXP)  	: 486 PC clone

  Operating System (example: OSF/1 3.2)  	: FreeBSD 2.0

  Postgres95 version (example: Postgres95-1.0) :   Postgres95-1.0

  Compiler used (example:  gcc 2.6.3)		: gcc 2.6.3


Please enter a FULL description of your problem:
------------------------------------------------

When you use "update xxxx set var1=var2", and var1 is an integer field,
while var2 is a real field (or vice versa), Postgres95 seems to just blindly
copy the bytes, without doing any kind of conversion (or complaining about
different data types). That produces odd numbers as a result.

This seems an error too obvious to have escaped, so please, anybody try this
out and confirm that the error is actually there.

Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible: 
----------------------------------------------------------------------

Execute the following SQL script and look at the results:

create table prueba (
	r	real,
	n	integer);

insert into prueba(r) values(15.0);
update prueba set n=r;
select * from prueba;
-- The above commands should give me one row whose two fields are both
-- '15' (or a complaint saying that they are different types). Instead,
-- Postgres95 seems to just copy the binary representation from the real
-- number into the integer number, resulting in an odd integer value
-- (1097859072).

update prueba set r=0.0;
select * from prueba;
update prueba set r=n;
select * from prueba;
-- A quick verification to demonstrate that Postgres95 just copies the
-- binary representation, instead of converting the actual value (or
-- complaining about different types).

delete from prueba;
insert into prueba(n) values(15);
update prueba set r=n;
select * from prueba;
-- Another demonstration of the same bug, this time starting with a
-- "good" integer value, and getting an odd real number (2.10195e-44).

If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------

Don't know yet, sorry. Postgres should ensure the data types of source
and destination operands are the same before copying the value.

It's funny, because this all started when I tried to execute:

update prueba set n=n*r/100;

And here, postgres tells me to use casting or define a "*" operator
for int4 and float4. Can anybody tell me how to cast that?


===============================================================================
  To unsubscribe from the Postgres95 mailing list, send mail with the subject
  line "DEL" to "postgres95-request@postgres.Berkeley.EDU". 
============  URL: http://s2k-ftp.CS.Berkeley.EDU:8000/postgres95/  ===========
