Re: [GENERAL] 7.3 -> pg_atoi: zero-length string

From: Henner Zeller <henner(at)freiheit(dot)com>
To: postgresql <pgsql-general(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [GENERAL] 7.3 -> pg_atoi: zero-length string
Date: 2002-12-03 17:07:52
Message-ID: Pine.LNX.4.44.0212031733490.6323-100000@kupfersulfat.toxine.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers


Hi,
| > What is the solution of other dbs ( oracle, db2 .. ) to:
| > insert into table (num) value (''); ? |
| I assume they would fail too.

The Oracle behaviour is:
---
oracle> create table foonum (x number(5));
oracle> insert into foonum values ('');
oracle> select * from foonum;
--------+
X |
--------+
[NULL] |
--------+
---

so, '' as numeric value is regarded as NULL. But Oracle
braindeadly interprets the varchar '' as well as NULL in a varchar
column so is probably not paragon ...

IMHO, if PostgreSQL is to support an empty string for numerics at all,
then it should be interpreted as not-a-value and as such as NULL.
Interpreting it as numeric value '0' could lead to subtle bugs since this
would probably not the expected behaviour (at least not mine).
The number '0' is arbitrary, except that we happend to start counting with
it. Someone else could argue why not interpret not-a-value as '1'
(non-computer guys tend to start counting with '1') or even '42' (since
this is the answer to everything).

I personally would be prefer to raise an error on an empty string; but
interpreting it as NULL would be reasonable as well. But interpreting it
as '0' will yield many unseen programming errors and should be avoided.

my 2cent,
-hen

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-12-03 17:12:12 Re: [HACKERS] 7.3 -> pg_atoi: zero-length string
Previous Message scott.marlowe 2002-12-03 17:01:17 Re: One SQL to access two databases.

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2002-12-03 17:12:12 Re: [HACKERS] 7.3 -> pg_atoi: zero-length string
Previous Message Magnus Naeslund(f) 2002-12-03 17:03:16 Re: Backend crash with tsearch