postgreSQL之类型转换
本文最后更新于 2494 天前,其中的信息可能已经有所发展或是发生改变。

以下是自己结合postgreSQL文档手册总结整理的入门手札,如有不严谨,请到官方文档手册查看:http://www.postgres.cn/docs/10/index.html


postgreSQL类型转换有三种方式:

  1. 通过格式化函数
  2. cast函数
  3. ::操作符

格式化函数

postgreSQL提供了很多内置的数据类型转换函数,如:

Image

例子练习:
 把时间戳转成字符串:
select to_char(current_timestamp, 'HH12:MI:SS')

把整数转成字符串:
select to_char(77777, '99999')

把实数或双精度转成字符串:
select to_char(125.8::real, '999D9')

把字符串转成日期:
select to_date('2019-10-20', 'YYYY-mm-dd')

 

cast函数

一个类型造型指定从一种数据类型到另一种数据类型的转换。PostgreSQL接受两种等价的类型造型语法:

CAST ( expression AS type )
expression::type
如将varchar字符类型转成text类型:

select cast(varchar'123' as text)
----
text
123
如将varchar字符类型转成int4类型:

select cast(varchar'123' as int4)
----
int4
123

::操作符

直接例子介绍吧,如:

select 1::int4,5/4::numeric
----
int4	?column?
1	1.25

如果想了解更多,可到:http://www.postgres.cn/docs/10/functions-formatting.html 查看~

码字不易要不打个赏?

Image
Image

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇