Supabase

读写行

查询、插入、更新、合并和删除行。

指南 →

/supabase/{database_id}/rest/v1/{table}

与同一库的其它入口读写相同的行;错误使用 PostgREST code。

支持矩阵与初始化

参数与请求头

名称位置说明
database_idpath库 ID。
tablepath表 ID 或名称。
selectquery列名列表;支持 *、别名、JSON 路径及 link 关联展开。不支持类型转换、聚合、展开运算和连接修饰。
{column}query把 {column} 换为字段名或 JSON 路径,例如 title=eq.summary;不同列的条件同时生效。
andquery括号内的条件全部成立,例如 (done.eq.false,title.neq.draft)。
orquery括号内任一条件成立。
not.andquery否定全部条件成立。
not.orquery否定任一条件成立。
orderquery逗号分隔的字段,可带 asc/desc、nullsfirst/nullslast;支持 JSON 路径。
limitquery最多返回的条数。
offsetquery跳过的行数。
on_conflictqueryupsert 的冲突键:id 或单个 unique 字段;配合 Prefer 的 resolution。
columnsquery写入列的逗号分隔列表;列表之外的输入键被忽略。
RangeheaderGET/HEAD 的闭区间,例如 0-9;与 limit/offset 取交集。
Range-Unitheaderitems;其它单位使 Range 被忽略。
Preferheader逗号分隔的偏好。未知值默认被忽略;handling=strict 时返回 400 PGRST122。
Acceptheaderapplication/json、/ 或 application/vnd.pgrst.object+json;单对象模式必须恰好匹配一行,否则返回 406 PGRST116。其他媒体类型返回 406 PGRST107;text/csv、application/geo+json 与 application/vnd.pgrst.plan 返回 400 PGRST127。
If-None-Matchheader上次 GET/HEAD 返回的 ETag(弱比较);与当前 ETag 匹配时返回 304,无正文。

POST 接受单个对象或对象数组;PATCH 接受对象。系统列由服务管理。写入默认不返回正文,使用 Prefer: return=representation(SDK 的 .select())返回行。PATCH 和 DELETE 只影响匹配过滤器的行;省略过滤器会影响全部匹配行。

响应头说明
Content-Range本次行范围/总数;未请求计数时总数为 *。
Preference-Applied已应用的偏好。
ETagGET/HEAD 返回的版本标记;请求带 If-None-Match 且与之匹配时返回 304、无正文。
LocationPOST 使用 return=headers-only 时的新行地址。

读取通常为 200;请求计数且只返回部分行时为 206。POST 为 201。PATCH/DELETE 使用 representation 时为 200,否则为 204。HEAD 没有正文。If-None-Match 与当前 ETag 匹配时返回 304。datetime 值统一按 UTC、3 位毫秒保存和读出(如 2026-10-11T00:30:00.000Z),精度为毫秒,超过 3 位的小数秒四舍五入。

查询行

GET /supabase/{database_id}/rest/v1/{table}

const { data, error } = await supabase.from("tasks").select("*").order("title").limit(10);
if (error) throw error;
console.log(data);

响应

HTTP 200

Success; write bodies require Prefer: return=representation

application/json

名称类型说明
[].idstring
[].versioninteger
[].created_atstring
[].updated_atstring

application/vnd.pgrst.object+json

名称类型说明
idstring
versioninteger
created_atstring
updated_atstring

HTTP 206

Partial range with requested count

application/json

名称类型说明
[].idstring
[].versioninteger
[].created_atstring
[].updated_atstring

application/vnd.pgrst.object+json

名称类型说明
idstring
versioninteger
created_atstring
updated_atstring

响应示例 — HTTP 200

响应头值
content-range0-0/*
etagW/"5.1"
range-unititems
[
  {
    "id": "rec_e88fcbd357aa49c9",
    "version": 1,
    "created_at": "2026-10-11T17:42:00.094Z",
    "updated_at": "2026-10-11T17:42:00.094Z",
    "title": "Write a summary",
    "done": false
  }
]

统计行

HEAD /supabase/{database_id}/rest/v1/{table}

const { data, error, count } = await supabase.from("tasks").select("*", { head: true, count: "exact" });
if (error) throw error;
console.log(count);

响应

HTTP 200

Success; write bodies require Prefer: return=representation

未声明响应体。

HTTP 206

Partial range with requested count

未声明响应体。

响应示例 — HTTP 200

响应头值
content-range0-0/1
preference-appliedcount=exact
etagW/"5.1"
range-unititems

无响应正文。

插入行

POST /supabase/{database_id}/rest/v1/{table}

const { data, error } = await supabase.from("tasks").insert({"title":"Write a summary","done":false}).select();
if (error) throw error;
console.log(data);

响应

HTTP 201

Success; write bodies require Prefer: return=representation

application/json

名称类型说明
[].idstring
[].versioninteger
[].created_atstring
[].updated_atstring

application/vnd.pgrst.object+json

名称类型说明
idstring
versioninteger
created_atstring
updated_atstring

响应示例 — HTTP 201

响应头值
content-range0-0/*
preference-appliedreturn=representation
range-unititems
[
  {
    "id": "rec_e88fcbd357aa49c9",
    "version": 1,
    "created_at": "2026-10-11T17:42:00.094Z",
    "updated_at": "2026-10-11T17:42:00.094Z",
    "title": "Write a summary",
    "done": false
  }
]

更新行

PATCH /supabase/{database_id}/rest/v1/{table}

const { data, error } = await supabase.from("tasks").update({ done: true }).eq("title", "Write a summary").select();
if (error) throw error;
console.log(data);

响应

HTTP 200

Success; write bodies require Prefer: return=representation

application/json

名称类型说明
[].idstring
[].versioninteger
[].created_atstring
[].updated_atstring

application/vnd.pgrst.object+json

名称类型说明
idstring
versioninteger
created_atstring
updated_atstring

HTTP 204

Success without a body

未声明响应体。

响应示例 — HTTP 200

响应头值
content-range0-0/*
preference-appliedreturn=representation
range-unititems
[
  {
    "id": "rec_e88fcbd357aa49c9",
    "version": 2,
    "created_at": "2026-10-11T17:42:00.094Z",
    "updated_at": "2026-10-11T17:42:01.047Z",
    "title": "Write a summary",
    "done": true
  }
]

合并行

POST /supabase/{database_id}/rest/v1/{table}

const { data, error } = await supabase.from("tasks").upsert({"title":"Write a summary","done":true}, { onConflict: "title" }).select();
if (error) throw error;
console.log(data);

响应

HTTP 201

Success; write bodies require Prefer: return=representation

application/json

名称类型说明
[].idstring
[].versioninteger
[].created_atstring
[].updated_atstring

application/vnd.pgrst.object+json

名称类型说明
idstring
versioninteger
created_atstring
updated_atstring

响应示例 — HTTP 201

响应头值
content-range0-0/*
preference-appliedresolution=merge-duplicates, return=representation
range-unititems
[
  {
    "id": "rec_e88fcbd357aa49c9",
    "version": 3,
    "created_at": "2026-10-11T17:42:00.094Z",
    "updated_at": "2026-10-11T17:42:01.735Z",
    "title": "Write a summary",
    "done": true
  }
]

删除行

DELETE /supabase/{database_id}/rest/v1/{table}

const { data, error } = await supabase.from("tasks").delete().eq("title", "Write a summary").select();
if (error) throw error;
console.log(data);

响应

HTTP 200

Success; write bodies require Prefer: return=representation

application/json

名称类型说明
[].idstring
[].versioninteger
[].created_atstring
[].updated_atstring

application/vnd.pgrst.object+json

名称类型说明
idstring
versioninteger
created_atstring
updated_atstring

HTTP 204

Success without a body

未声明响应体。

响应示例 — HTTP 200

响应头值
content-range0-0/*
preference-appliedreturn=representation
range-unititems
[
  {
    "id": "rec_e88fcbd357aa49c9",
    "version": 3,
    "created_at": "2026-10-11T17:42:00.094Z",
    "updated_at": "2026-10-11T17:42:01.735Z",
    "title": "Write a summary",
    "done": true
  }
]
导出

本页内容