PostgreSQL:默认情况下 0 和 (0)::smallint 之间有什么区别?

PostgreSQL: what is the difference between 0 and (0)::smallint as default?

我正在研究列类型和默认值,遇到了两列,都是 smallint 但具有不同的默认值:

  1. 0
  2. (0)::smallint

当我将 2 更改为 1 的值时,两者都是一样的,似乎没有任何变化。当然,我用 google 搜索了我的问题的答案,发现 :: 用于类型转换。但我想知道,如果它是默认值,为什么需要类型转换?

没有区别,不需要强制转换

# create table somesmallints (a smallint default 0, b smallint default 0::smallint, c smallint default (0)::smallint);

CREATE TABLE
# \d+ somesmallints;
                                  Table "public.somesmallints"
 Column |   Type   | Collation | Nullable |    Default    | Storage | Stats target | Description 
--------+----------+-----------+----------+---------------+---------+--------------+-------------
 a      | smallint |           |          | 0             | plain   |              | 
 b      | smallint |           |          | (0)::smallint | plain   |              | 
 c      | smallint |           |          | (0)::smallint | plain   |              | 

# select 0 = 0::smallint;
 ?column? 
----------
 t
(1 row)