new at_tz function, closes #81267

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changesetd9a0df4bdb91
branchdefault
phasepublic
hiddenno
parent revision#1bf49a437e30 add a process_cursor method (closes #77769)
child revision#690a4d13f0a3 pkginfo: use setup.py from logilab.common
files modified by this revision
ChangeLog
__init__.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1319454326 -7200
# Mon Oct 24 13:05:26 2011 +0200
# Node ID d9a0df4bdb91d7b497e1d79246ca28f0122e523b
# Parent 1bf49a437e305168aec5d3fb009b52674b35e8a0
new at_tz function, closes #81267

diff --git a/ChangeLog b/ChangeLog
@@ -1,10 +1,11 @@
1  Changelog for logilab database package
2  ======================================
3 
4    --  1.8.0
5      * process_cursor (closes #77769)
6 +    * new "at_tz" function to get back a timestamp at a given time-zone (closes #81267)
7 
8  2011-10-17 -- 1.7.0
9      * new WEEKDAY date extraction function
10      * sqlserver support for other existing date extraction function, added
11  	helper to get list of VIEWs
diff --git a/__init__.py b/__init__.py
@@ -550,10 +550,19 @@
12 
13      def as_sql_postgres(self, args):
14          # for postgres, sunday is 0
15          return '(CAST(EXTRACT(DOW from %s) AS INTEGER) + 1)' % (', '.join(args))
16 
17 +class AT_TZ(FunctionDescr):
18 +    """AT_TZ(TZDatetime, timezone) -> Return a datetime at a given time zone.
19 +    """
20 +    supported_backends = ('postgres',)
21 +    minargs = maxargs = 2
22 +
23 +    def as_sql_postgres(self, args):
24 +        return "%s at time zone %s" % tuple(args)
25 +
26 
27  class CAST(FunctionDescr):
28      """usage is CAST(datatype, expression)
29 
30      sql-92 standard says (CAST <expr> as <type>)
@@ -611,11 +620,11 @@
31      MIN, MAX, SUM, COUNT, AVG,
32      # transformation functions
33      ABS, RANDOM,
34      UPPER, LOWER, SUBSTRING, LENGTH,
35      DATE,
36 -    YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, WEEKDAY,
37 +    YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, WEEKDAY, AT_TZ,
38      # cast functions
39      CAST,
40      # keyword function
41      IN):
42      SQL_FUNCTIONS_REGISTRY.register_function(func_class())