从连接日期和时间列获取时间戳 [英] Get a timestamp from concatenating day and time columns

查看:168
本文介绍了从连接日期和时间列获取时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有日期和时间字段。我想通过连接日期和时间来获得时间戳。如何在PostgreSQL中做到这一点?

I am having day and time fields in database. I want to get the time-stamp by concatenating the day and time. How to do this in PostgreSQL?

我这样做:

SELECT EXTRACT(EPOCH FROM TIMESTAMP '2011-05-17 10:40:28');

它工作正常。

但是当我试图替换日期和时间字段时,我得到以下错误:

But when I tried replacing day and time fields I am getting the following error:

SELECT EXTRACT(EPOCH FROM TIMESTAMP Day || ' ' || Time);




ERROR:  syntax error at or near "Day"
LINE 1: ...quest_count > 0 AND (EXTRACT(EPOCH FROM TIMESTAMP Day || ' ' || Time)) > (e...



推荐答案

SELECT EXTRACT(EPOCH FROM (Day || ' ' || Time)::timestamp);

这篇关于从连接日期和时间列获取时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆