暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Pg格式化函数

原创 万事如意 2023-03-10
359

PostgreSQL格式化函数提供一套有效的工具用于把各种数据类型(日期/时间、integer、floating point和numeric)转换成格式化的字符串以及反过来从格式化的字符串转换成指定的数据类型。下面列出了这些函数,它们都遵循一个公共的调用习惯:第一个参数是待格式化的值,而第二个是定义输出或输出格式的模板。

函数

返回类型

描述

例子

to_char(timestamp, text)

text

把时间戳转换成字串

to_char(current_timestamp, 'HH12:MI:SS')

to_char(interval, text)

text

把时间间隔转为字串

to_char(interval '15h 2m 12s', 'HH24:MI:SS')

to_char(int, text)

text

把整数转换成字串

to_char(125, '999')

to_char(double precision, text)

text

把实数/双精度数转换成字串

to_char(125.8::real, '999D9')

to_char(numeric, text)

text

把numeric转换成字串

to_char(-125.8, '999D99S')

to_date(text, text)

date

把字串转换成日期

to_date('05 Dec 2000', 'DD Mon YYYY')

to_timestamp(text, text)

timestamp

把字串转换成时间戳

to_timestamp('05 Dec 2000', 'DD Mon YYYY')

to_timestamp(double)

timestamp

把UNIX纪元转换成时间戳

to_timestamp(200120400)

to_number(text, text)

numeric

把字串转换成numeric

to_number('12,454.8-', '99G999D9S')

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论