"JSON does not support infinite date values"

From: Tim Smith <randomdev4+postgres(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: "JSON does not support infinite date values"
Date: 2015-02-26 11:55:20
Message-ID: CA+HuS5HrCLtFsMPsp+2xt7nv4tBws7JDHhxngYZ73VWJOMyMiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

As far as I'm aware, JSON has no data types as such, and so why is
Postgres (9.4.1) attempting to impose its own nonsense constraints ?
Surely it should just insert the word 'infinity' into the JSON output,
just like it displays in a simple SQL query ?

create table app_test.foo(a text,b date,c date,d boolean);

create view app_test.bar as select * from app_test.foo where
b<=now()::date and c>=now()::date and d=true;

insert into app_test.foo(a,b,c,d) values ('zzz','2014-12-31','2014-02-01',true);
insert into app_test.foo(a,b,c,d) values ('zzz','2015-02-01','infinity',true);

foobar=> select * from app_test.bar where a='zzz' order by c asc limit 1;
a | b | c | d
-----+------------+----------+---
zzz | 2015-02-01 | infinity | t
(1 row)

CREATE FUNCTION app_test.foobar(p_a text) RETURNS json AS $$
DECLARE
v_row app_test.bar%ROWTYPE;
v_json json;
BEGIN
select * into strict v_row from app_test.bar where a=p_a order by c asc limit 1;
select row_to_json(v_row) into v_json;
return v_json;
END;
$$ LANGUAGE plpgsql;

foobar=> select app_test.foobar('zzz');
ERROR: date out of range
DETAIL: JSON does not support infinite date values.
CONTEXT: SQL statement "select row_to_json(v_row)"
PL/pgSQL function app_test.foobar(text) line 7 at SQL statement

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andres Freund 2015-02-26 12:02:23 Re: "JSON does not support infinite date values"
Previous Message Torsten Förtsch 2015-02-26 11:23:03 Locking question