Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

创建/删除 表

CREATE 创建

CREATE TABLE public.table_name (
    "user_uuid" uuid NOT NULL,
    "device_uuid" uuid,
    "type" varchar(32) NULL,
    "data" jsonb DEFAULT '{}',
    "removed" int2 NULL DEFAULT 0,
    "ctime" timestamp with time zone NULL,
    "mtime" timestamp with time zone NULL
);
  • 字符串类型
    • (最常用)varchar(n)character varying(n) 等价
      • 有var
        • 所以长度可变,但不得超过n
      • 如果不指定n
        • 那可以随意扩展,最大长度是10485760(1GB)
    • (尽量少用)char(n)character(n) 等价
      • 无var
        • 所以固定长度为n,不足会补空白
      • 如果不指定n
        • 则默认长度是1
    • (最灵活)text
      • 变长,但无长度限制

DROP 删除

DROP TABLE public.table_name;
  • 会彻底删除表

  • 如果只是清空表中所有内容,可以用TRUNCATE

    TRUNCATE public.table_name;