BIGINT 和 INT8 有什么区别?(postgres)

use*_*934 17 postgresql

我正在使用名为 Supabase 的服务,并创建了一个表:

CREATE TABLE my_table ( 
    "id" BIGSERIAL PRIMARY KEY NOT NULL,
    "title" Text COLLATE "pg_catalog"."default",
    "message" Text COLLATE "pg_catalog"."default");
Run Code Online (Sandbox Code Playgroud)

但是,这会变成 int8 类型。比bigint小吗?

Luk*_*der 18

BIGINT只是 PostgreSQL 中的别名INT8。尝试这个:

CREATE TABLE t (
  c1 bigint,
  c2 int8
);

SELECT a.attname, t.typname
FROM pg_class AS c 
JOIN pg_attribute AS a ON a.attrelid = c.oid
JOIN pg_type AS t ON a.atttypid = t.oid
WHERE c.relname = 't'
AND a.attname IN ('c1', 'c2')
ORDER BY 1;
Run Code Online (Sandbox Code Playgroud)

你会得到:

|attname|typname|
|-------|-------|
|c1     |int8   |
|c2     |int8   |
Run Code Online (Sandbox Code Playgroud)

bigint中没有存储类型名称pg_type

SELECT * FROM pg_type WHERE typname IN ('int8', 'bigint');
Run Code Online (Sandbox Code Playgroud)

这只返回:

|typname|
|-------|
|int8   |
Run Code Online (Sandbox Code Playgroud)