DB2 timestamp default

Posted on 2012-08-31
Last Modified: 2012-08-31
Hi all,

Is that possible to create a column with default of UTC timestamp?

instead of:
      DT_WHEN TIMESTAMP DEFAULT current timestamp NOT NULL, .....

I tried
      DT_WHEN TIMESTAMP DEFAULT(current  timestamp - current timezone) NOT NULL, .....

but it gives me an error.

Please help,

Question by:darrgyas
    LVL 18

    Expert Comment

    Isn't the current timezone the default for current timestamp?
    LVL 45

    Accepted Solution

    The CURRENT TIMEZONE special register is a integer value that contains the number of hours, minutes, and seconds that the CURRENT TIMESTAMP (and date, time registers) vary from UTC.
    db2 => select current_timezone from sysibm.sysdummy1


      1 record(s) selected.

    IBM does tend to over-engineer a lot of stuff, and this is one of them.  The expanded value allows you to adjust the time even for an oddball time zone that varies by fractions of an hour.

    Anyway, you can't do what you're trying to do.  IBM allows very limited calculations in a generating a default value.

    Depending on your version of DB2, you CAN declare the column as TIMESTAMP WITH TIMEZONE.  Db2 will store the timestamp in UTC and maintain the timezone along with the value.

    As far as I know, that feature isn't in DB2/LUW (yet).  But it is in the Z/OS version.


    Author Comment

    Thank you, that explains it

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Salary Amount Format 13 50
    Select distinct 25 40
    TSQL Update Field Older Than 5 Days 10 36
    Php Sql Query 7 19
    Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now