Re: Tightening binary receive functions

James William Pye <lists@jwp.name>

From: James Pye <lists@jwp.name>
To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2009-10-24T16:22:34Z
Lists: pgsql-hackers
On Aug 31, 2009, at 1:12 AM, Heikki Linnakangas wrote:
> ...


Is the new date_recv() constraint actually correct?

[looking at the "result < 0" part, at least]

src/backend/utils/adt/date.c
...
+       /* Limit to the same range that date_in() accepts. */
+       if (result < 0 || result > JULIAN_MAX)
+               ereport(ERROR,
+                               (errcode 
(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+                                errmsg("date out of range")));
+
+       PG_RETURN_DATEADT(result);
  }


postgres=# SELECT date_send('500-01-01'::date);
  date_send
------------
  \xfff7a3e9
(1 row)

...

 >>> struct.unpack("!l", b'\xff\xf7\xa3\xe9')
(-547863,)


Perhaps 'result' needs to be adjusted by the postgres epoch for the  
comparison?