Automatic type conversion

From: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>
To: Postgres Hackers List <hackers(at)postgresql(dot)org>
Cc: Postgres Patches List <patches(at)postgresql(dot)org>
Subject: Automatic type conversion
Date: 1998-05-10 00:14:11
Message-ID: 3554F153.2B09C37B@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I've committed changes to allow more automatic type conversion. Lots of
files were touched, mostly in backend/parser/.

The new code tries to do the right thing for conversions, and does
handle cases which were problematic before:

-- there isn't a floating point factorial operator...
tgl=> select (4.3 !);
?column?
--------
24
(1 row)

-- there isn't an integer exponentiation operator...
tgl=> select 2 ^ 3;
?column?
--------
8
(1 row)

-- concatenation on unspecified types didn't used to work...
tgl=> select '123' || '456';
?column?
--------
123456
(1 row)

-- didn't used to correctly truncate strings into tables...
tgl=> create table cc (c char(4));
CREATE
tgl=> insert into cc select '123' || '456';
INSERT 268073 1
tgl=> select * from cc;
c
----
1234
(1 row)

So, it should fix longstanding issues. However, the main goal should be
that it doesn't do the WRONG thing at any time. So, test away and post
any problems or issues that come up; we have lots of time to fix things
before v6.4.

One change in behavior is that I defined (for builtin types) the concept
of a "preferred type" in each category/class of types (e.g. float8 is
the preferred type for numerics, datetime is the preferred type for
date/times, etc.). And, unspecified types are preferentially resolved to
use this preferred type. So, the following behavior has changed:

-- this is now done as a float8 calculation, used to be float4...
tgl=> select '123.456'::float4 * '1.99999999999';
?column?
----------------
246.912002562242
(1 row)

Before, unknown types, such as the second string above, were resolved to
be the same type as the other type, if available. So the calculation
would have been truncated at ~7 decimal places.

The good thing about this is that the behavior of the above is now the
same as if the second string was specified without the quotes:

tgl=> select '123.456'::float4 * 1.99999999999;
?column?
----------------
246.912002562242
(1 row)

where before it was evaluated differently in the two cases.

Anyway, try things out, and I'll be writing this up for the docs. Will
post the topics on hackers along the way...

I haven't yet changed the regression tests to reflect the new behavior,
just in case it needs to be different. Also, all regression tests pass
with the only differences as mentioned above. btw, the code still has
lots of cleanup needed, moving subroutines around and taking out defunct
code. But will do that later.

Have fun.

- Tom

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Byron Nikolaidis 1998-05-10 00:15:37 Re: [INTERFACES] NEW ODBC DRIVER
Previous Message Byron Nikolaidis 1998-05-10 00:12:21 Re: [INTERFACES] NEW ODBC DRIVER