3

使用 postgres 12.2:

select '46ee2794-ddd1-4c4b-be04-82908ff1885d'::"uuid" /*works, uuid is a built-in type, not an alias*/
select '1'::"int4"    /*works ... int4 is alias for integer*/
select '1'::"integer" /*fails ... integer is built-in type*/

我已经放弃了双引号,但仍然很好奇为什么它会这样!

4

1 回答 1

2

如果我们假设基本类型存储在系统目录中,这可能看起来很奇怪,但实际上int4是一种基本类型,而它是一种别名。integerpg_type

select oid, typname
from pg_type
where typname like 'int%'
and typcategory = 'N'

 oid | typname
-----+---------
  20 | int8
  21 | int2
  23 | int4
(3 rows)
于 2020-02-25T18:09:46.510 回答