Skip site navigation (1) Skip section navigation (2)

Re: Range Type Support

From: Federico Di Gregorio <fog(at)dndg(dot)it>
To: psycopg(at)postgresql(dot)org
Subject: Re: Range Type Support
Date: 2012-09-20 07:48:04
Message-ID: 505ACA34.8040803@dndg.it (view raw or flat)
Thread:
Lists: psycopg
On 20/09/2012 02:18, Daniele Varrazzo wrote:
>>> - Possibly it should support an "in" operator and an & operator. But
>>> >> then, should we mimic all the operators?
>>> >> <http://www.postgresql.org/docs/9.2/static/functions-range.html>
>>> >> Probably not.
>> >
>> > By "&" do you mean "&&"?  Part of me thinks we should support overlaps, but part of the power of the range types feature is that Postgres can handle overlap operations (which are nontrivial to build).  I see "in" being used a lot.
> There's no && operator in python. But you are sorta right: I was
> thinking about an operator saying if two intervals match, not to
> return their intersection. But would it be any useful? It's definitely
> little thing compared to the richness of the postgres range type and
> implementing all of them is a project on its own. "in" otoh would be
> easy to implement.
> 

After we have a basic range type we can add operators as methods (IMO,
in this case operator "overloading" in Python is not what we want). So
you can have:

range1.overlaps(range2)
range1.inside(range2)

and so on. "in" can be an alias for one of such methods.

In fact a range type is so useful that I am amazed it doesn't already
exists in Python.

federico

-- 
Federico Di Gregorio                         federico(dot)digregorio(at)dndg(dot)it
Studio Associato Di Nunzio e Di Gregorio                  http://dndg.it
  Qu'est ce que la folie? Juste un sentiment de liberté si
   fort qu'on en oublie ce qui nous rattache au monde... -- J. de Loctra


In response to

psycopg by date

Next:From: Tobias ObersteinDate: 2012-09-20 21:50:46
Subject: flexi adaption/casting scheme
Previous:From: Daniele VarrazzoDate: 2012-09-20 00:18:50
Subject: Re: Range Type Support

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group