Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWQYR-0001MR-9O for pgsql-sql@arkaria.postgresql.org; Wed, 16 Oct 2013 12:50:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VWQYQ-0008Ll-K9 for pgsql-sql@arkaria.postgresql.org; Wed, 16 Oct 2013 12:50:22 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWQYP-0008Le-H1 for pgsql-sql@postgresql.org; Wed, 16 Oct 2013 12:50:21 +0000 Received: from teak.britvault.co.uk ([78.33.153.148]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWQYL-0000RJ-N9 for pgsql-sql@postgresql.org; Wed, 16 Oct 2013 12:50:20 +0000 Received: by teak.britvault.co.uk (Postfix, from userid 1970) id 3d0Cyv1PGWzB9g; Wed, 16 Oct 2013 13:50:15 +0100 (BST) Date: Wed, 16 Oct 2013 13:50:14 +0100 To: pgsql-sql@postgresql.org Subject: PostgreSQL 9.2 tstzrange null/infinity CONSTRAINT CHECK Message-ID: <20131016125014.GA25474@teak.britvault.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) From: skinner@britvault.co.uk (Craig R. Skinner) X-Pg-Spam-Score: -1.0 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org I'd like to limit a 9.2 tstzrange to valid dates at both ends. No NULLs nor 'infinity'. Various revisions of this SQL isn't constraining '-/+infinity' input: CREATE TABLE bill ( id serial NOT NULL, created_at timestamp with time zone NOT NULL DEFAULT now(), period tstzrange NOT NULL, -- other columns CONSTRAINT bill_pk PRIMARY KEY (id), CONSTRAINT bill_period_lower_not_null_ck CHECK (lower(period) IS NOT NULL), CONSTRAINT bill_period_upper_not_null_ck CHECK (upper(period) IS NOT NULL), CONSTRAINT bill_period_lower_not_infinity_ck CHECK (lower_inf(period) IS FALSE), CONSTRAINT bill_period_upper_not_infinity_ck CHECK (upper_inf(period) IS FALSE) ); INSERT INTO bill (period) VALUES (tstzrange (NULL, NULL)); INSERT INTO bill (period) VALUES (tstzrange ('2000-05-10', '2015-02-22'); INSERT INTO bill (period) VALUES (tstzrange ('2000-05-10', now()); INSERT INTO bill (period) VALUES (tstzrange ('infinity', now()); INSERT INTO bill (period) VALUES (tstzrange ('-infinity', now()); INSERT INTO bill (period) VALUES (tstzrange (now(), 'infinity'); psql (9.2.3) Type "help" for help. test_1=> SELECT id, period FROM bill; id | period ----+------------------------------------------------------------ 1 | ["2000-05-10 00:00:00+01","2015-02-22 00:00:00+00") 2 | ["2000-05-10 00:00:00+01","2013-10-16 13:20:01.793803+01") 4 | [-infinity,"2013-10-16 13:20:18.993038+01") 5 | ["2013-10-16 13:21:14.208279+01",infinity) (4 rows) Changing the *_inf(period) IS FALSE checks to TRUE rejects valid dates. Range functions in the manual: http://www.postgresql.org/docs/9.2/static/functions-range.html Thoughts? -- Craig Skinner | http://twitter.com/Craig_Skinner | http://linkd.in/yGqkv7 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql