Add the unix_timestamp and from_unixtime functions of MySQL to PostgreSQL.

Source: Internet
Author: User

Two common functions of MySQL, unix_timestamp () and from_unixtime PostgreSQL, are not provided, but they can be easily solved through the powerful scalability of PostgreSQL.

The words are far away from the sky, and the documents are carefully read. PostgreSQL provides epoch for extract and date_part.
That is
Unix_timestamp () = round (date_part ('epoch', now ()))
From_unixtime (int) = to_timestamp (int)

Add function unix_timestamp ()
Create function unix_timestamp () RETURNS integer AS $
SELECT (date_part ('epoch', now (): integer;
$ Language SQL IMMUTABLE;

Add function from_unixtime ()
Create function from_unixtime (int) RETURNS timestamp AS $
SELECT to_timestamp ($1): timestamp;
$ Language SQL IMMUTABLE;

 

From: http://www.jiangmiao.org/blog/430.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.