You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PostgreSQL创建整数序列?Supabase语法错误排查

问题排查与解决

错误根源

你的SQL代码中,products表定义的最后一个字段featured integer references featured (id),末尾多了一个逗号,这会导致数据库解析时出现语法错误,对应提示的syntax error at or near ")"。

修正后的完整代码

create sequence product_id_seq
    start with 100
    increment by 1
    no maxvalue
    no minvalue;

create table products 
(
    id int4 not null default nextval('product_id_seq'),
    name text not null,
    price numeric(10,2) not null,
    description text,
    category_id integer references categories (id),
    preview text,
    images text[],
    stock integer not null,
    sale boolean,
    sale_price numeric(10,2),
    sale_text text,
    featured integer references featured (id),
    primary key (id)
);

补充说明

  1. 序列创建的语法完全合规,no maxvalue和no minvalue符合PostgreSQL(Supabase基于PostgreSQL)的规则,也可以直接省略——因为序列默认就是无最大、最小值限制。
  2. 执行前请确认categories和featured这两张被外键关联的表已经存在,否则会触发外键关联错误。

内容的提问来源于stack exchange,提问作者Mintee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 08:24:58