Re: How to add explicit types so I can use OVERLAPS?
Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Organization | initd.org |
| Message-ID | <[email protected]> |
Il giorno ven, 01/08/2008 alle 14.47 +0000, Matthew Wilson ha scritto:
> I want to use the OVERLAPS keyword to compare two time intervals, but
> I'm having trouble.
>
> In the code below, I want to test if the time interval from 9:15 AM
> through 9:45 AM overlaps the time interval from 8 AM through 10 AM.
>
> This approach fails:
>
> >>> d = {'9:15 AM':datetime(2008, 8, 1, 9, 15),
> ... '9:45 AM':datetime(2008, 8, 1, 9, 45),
> ... '8 AM':datetime(2008, 8, 1, 8),
> ... '10 AM':datetime(2008, 8, 1, 10)}
>
> >>> cursor.execute('select (%(9:15 AM)s, %(9:45 AM)s) '
> ... 'overlaps (%(8 AM)s, %(10 AM)s);', d)
>
> ------------------------------------------------------------
> Traceback (most recent call last):
> File "<ipython console>", line 1, in <module>
> ProgrammingError: function pg_catalog.overlaps(unknown, unknown,
> unknown, unknown) is not unique
> LINE 1: ...ct ('2008-08-01T09:15:00', '2008-08-01T09:45:00') overlaps
> (...
> ^
> HINT: Could not choose a best candidate function. You might need to add
> explicit type casts.
>
> Meanwhile, this approach works fine:
>
> >>> cursor.execute('select (TIMESTAMP %(9:15 AM)s, TIMESTAMP %(9:45 AM)s) '
> 'overlaps (TIMESTAMP %(8 AM)s, TIMESTAMP %(10 AM)s);', d)
>
> >>> cursor.fetchall()
> [(True,)]
>
> For a lot of boring reasons, I don't want to go into all my code and add
> the TIMESTAMP cast.
>
> Is there anything else possible?
This is PostgreSQL 8.3 not automatically casting anymore. We should
probably change some of the getquoted() methods of the adapters to make
sure they add a (backend) typecast. And yes, patches are welcome.
federico
--
Federico Di Gregorio http://people.initd.org/fog
Debian GNU/Linux Developer [email protected]
INIT.D Developer fog-NGVKUo/i/[email protected]
heisenbug /hi:'zen-buhg/ /n./ [from Heisenberg's Uncertainty Principle
in quantum physics] A bug that disappears or alters its behavior when
one attempts to probe or isolate it.
_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc
(application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAkiTbRUACgkQvcCgrgZGjetpLgCeLZWe6PXND22L0Zfj+YN+gYiR 1ewAoJ269+bNfpfRPhtls2ujRV+OMCCu =VWJ4 -----END PGP SIGNATURE-----