Re: [GENERAL] 7.3 -> pg_atoi: zero-length string - Mailing list pgsql-hackers

From Henner Zeller
Subject Re: [GENERAL] 7.3 -> pg_atoi: zero-length string
Date
Msg-id Pine.LNX.4.44.0212031733490.6323-100000@kupfersulfat.toxine.lan
Whole thread Raw
In response to Re: [GENERAL] 7.3 -> pg_atoi: zero-length string  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
Hi,| > What is the solution of other dbs ( oracle, db2 .. ) to:| > insert into table (num) value (''); ? | | I assume
theywould 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



pgsql-hackers by date:

Previous
From: "Magnus Naeslund(f)"
Date:
Subject: Re: Backend crash with tsearch
Next
From: Hannu Krosing
Date:
Subject: Re: 7.4 Wishlist