跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • Postgres to_timestamp() 无法转换 unix epoch 字符串
未分類
2 10 月 2020

Postgres to_timestamp() 无法转换 unix epoch 字符串

Postgres to_timestamp() 无法转换 unix epoch 字符串

資深大佬 : nuistzhou 2

表结构如下:

create table item (  "ID" varchar not null,  "unixTime" varchar not null, ); 

现在

SELECT TO_TIMESTAMP("unixTime"); 

就总是提示
ERROR: function to_timestamp(character varying) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts.

但随手试了几个值都没啥问题,比如:
select to_timestamp(‘1358121600’);
select to_timestamp(‘969408000’);

初步怀疑表里有不同 format 的 timestamp 的值,然后 to_timestamp()不能根据不同的 format 自动智能转换?
有没有大佬可以启发下,看这样的情况怎么解决,急急急~谢谢谢谢

大佬有話說 (12)

  • 資深大佬 : hooopo

    SELECT TO_TIMESTAMP(unixTime);

  • 主 資深大佬 : nuistzhou

    @hooopo 这个不是问题啦,postgres 里字段名有大写的话要加双引号的~

  • 資深大佬 : hooopo

    很简单啊 先用 limit 1 测试下是不是数据问题 数据问题就修数据

  • 主 資深大佬 : nuistzhou

    @hooopo Limit 1 也报错,而且 80M 条数据,没法测呀,我倒是想有个函数可以把这些 invalid 的数据排除出去。。。

  • 資深大佬 : hooopo

    一个正则就行啊

  • 資深大佬 : MoYi123

    select TO_TIMESTAMP(“unixTime”::int) from item;

  • 主 資深大佬 : nuistzhou

    @MoYi123 完美!!感谢感谢老哥

  • 資深大佬 : sagaxu

    不能查一下手册看看这个函数的定义?

  • 資深大佬 : sfqtsh

    df to_timestamp

    你看有 character varying 参数的吗?

    显然没有!

  • 主 資深大佬 : nuistzhou

    @sfqtsh 有支持 string 啊

  • 資深大佬 : sfqtsh

    @nuistzhou 那是 format function 一种,且有两个参数。

    to_timestamp ( text, text ) → timestamp with time zone

    Converts string to time stamp according to the given format. (See also to_timestamp(double precision) in Table 9.32.)

    to_timestamp(’05 Dec 2000′, ‘DD Mon YYYY’) → 2000-12-05 00:00:00-05

  • 主 資深大佬 : nuistzhou

    @sfqtsh 哦,你说的对。
    我需要的其实是这个:
    “`
    to_timestamp ( double precision ) → timestamp with time zone

    Convert Unix epoch (seconds since 1970-01-01 00:00:00+00) to timestamp with time zone

    to_timestamp(1284352323) → 2010-09-13 04:32:03+00
    “`

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具