PostgreSQL基础:三种数据类型转换方式

1,272 阅读1分钟
  • 通过"类型名"加上单引号括起来的类型值格式进行转换
postgres=# select time '23:45:00';
   time
----------
 23:45:00
(1 row)

postgres=# select int '24' * int '10';
 ?column?
----------
      240
(1 row)
  • 通过类型转换函数CAST进行转换
postgres=# select CAST('10' as int),CAST('2021-12-05' as date);
 int4 |    date
------+------------
   10 | 2021-12-05
(1 row)
  • 通过双冒号方式进行转换
postgres=# select '10'::int,'2021-12-05'::date;
 int4 |    date
------+------------
   10 | 2021-12-05
(1 row)