Files
leaudit-platform-frontend/PostgREST 12.2 文档 .html
T

834 lines
62 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<!-- saved from url=(0064)https://postgrest.postgresql.ac.cn/en/v12/references/errors.html -->
<html lang="zh-hans" class="writer-html5" data-content_root="../" data-theme="light"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/f.txt"></script><script>(l=location)[p='protocol'][5]||(l[p]='https')</script><meta name="referrer" content="no-referrer"><script async="" src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/f(1).txt" crossorigin="anonymous" data-checked-head="true"></script>
<script>window.minimalAnalytics={trackingId:'G-M2CNWZ52HJ',autoTrack:true}</script>
<script async="" src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/index.js.下载"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>错误 — PostgREST 12.2 文档 - PostgREST 中文</title>
<link rel="stylesheet" type="text/css" href="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/pygments.css">
<link rel="stylesheet" type="text/css" href="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/theme.css">
<link rel="stylesheet" type="text/css" href="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/copybutton.css">
<link rel="stylesheet" type="text/css" href="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/custom.css">
<link rel="stylesheet" type="text/css" href="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/tabs.css">
<link rel="stylesheet" type="text/css" href="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/general.css">
<link rel="stylesheet" type="text/css" href="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/dark.css">
<link rel="shortcut icon" href="https://postgrest.postgresql.ac.cn/en/v12/_static/favicon.ico">
<link rel="canonical" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html">
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/jquery.js.下载"></script>
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/_sphinx_javascript_frameworks_compat.js.下载"></script>
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/documentation_options.js.下载"></script>
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/doctools.js.下载"></script>
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/sphinx_highlight.js.下载"></script>
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/clipboard.min.js.下载"></script>
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/copybutton.js.下载"></script>
<script async="async" src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/readthedocs-doc-embed.js.下载"></script>
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/default_light.js.下载"></script>
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/theme_switcher.js.下载"></script>
<script src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/theme.js.下载"></script>
<link rel="index" title="Index" href="https://postgrest.postgresql.ac.cn/en/v12/genindex.html">
<link rel="search" title="Search" href="https://postgrest.postgresql.ac.cn/en/v12/search.html">
<link rel="next" title="Configuration" href="https://postgrest.postgresql.ac.cn/en/v12/references/configuration.html">
<link rel="prev" title="Schema Cache" href="https://postgrest.postgresql.ac.cn/en/v12/references/schema_cache.html">
<link rel="stylesheet" href="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/readthedocs-doc-embed.css" type="text/css">
<script type="application/json" id="READTHEDOCS_DATA">{"ad_free": true, "api_host": "https://readthedocs.org", "builder": "sphinx", "canonical_url": null, "docroot": "/docs/", "features": {"docsearch_disabled": false}, "global_analytics_code": "UA-17997319-1", "language": "en", "page": "references/errors", "programming_language": "py", "project": "postgrest", "proxied_api_host": "/_", "source_suffix": ".rst", "subprojects": {}, "theme": "sphinx_rtd_theme", "user_analytics_code": "G-5CGB3QTKF1", "version": "v12"}</script>
<script type="text/javascript">
READTHEDOCS_DATA = JSON.parse(document.getElementById('READTHEDOCS_DATA').innerHTML);
</script>
<script type="text/javascript" src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/readthedocs-analytics.js.下载" async="async"></script>
<meta http-equiv="origin-trial" content="AlK2UR5SkAlj8jjdEc9p3F3xuFYlF6LYjAML3EOqw1g26eCwWPjdmecULvBH5MVPoqKYrOfPhYVL71xAXI1IBQoAAAB8eyJvcmlnaW4iOiJodHRwczovL2RvdWJsZWNsaWNrLm5ldDo0NDMiLCJmZWF0dXJlIjoiV2ViVmlld1hSZXF1ZXN0ZWRXaXRoRGVwcmVjYXRpb24iLCJleHBpcnkiOjE3NTgwNjcxOTksImlzU3ViZG9tYWluIjp0cnVlfQ=="><meta http-equiv="origin-trial" content="Amm8/NmvvQfhwCib6I7ZsmUxiSCfOxWxHayJwyU1r3gRIItzr7bNQid6O8ZYaE1GSQTa69WwhPC9flq/oYkRBwsAAACCeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXN5bmRpY2F0aW9uLmNvbTo0NDMiLCJmZWF0dXJlIjoiV2ViVmlld1hSZXF1ZXN0ZWRXaXRoRGVwcmVjYXRpb24iLCJleHBpcnkiOjE3NTgwNjcxOTksImlzU3ViZG9tYWluIjp0cnVlfQ=="><meta http-equiv="origin-trial" content="A9wSqI5i0iwGdf6L1CERNdmsTPgVu44ewj8QxTBYgsv1LCPUVF7YmWOvTappqB1139jAymxUW/RO8zmMqo4zlAAAAACNeyJvcmlnaW4iOiJodHRwczovL2RvdWJsZWNsaWNrLm5ldDo0NDMiLCJmZWF0dXJlIjoiRmxlZGdlQmlkZGluZ0FuZEF1Y3Rpb25TZXJ2ZXIiLCJleHBpcnkiOjE3MzY4MTI4MDAsImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"><meta http-equiv="origin-trial" content="A+d7vJfYtay4OUbdtRPZA3y7bKQLsxaMEPmxgfhBGqKXNrdkCQeJlUwqa6EBbSfjwFtJWTrWIioXeMW+y8bWAgQAAACTeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXN5bmRpY2F0aW9uLmNvbTo0NDMiLCJmZWF0dXJlIjoiRmxlZGdlQmlkZGluZ0FuZEF1Y3Rpb25TZXJ2ZXIiLCJleHBpcnkiOjE3MzY4MTI4MDAsImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"><script async="" src="https://fundingchoicesmessages.google.com/i/ca-pub-8543159550507237?href=https%3A%2F%2Fpostgrest.postgresql.ac.cn%2Fen%2Fv12%2Freferences%2Ferrors.html&amp;ers=2"></script></head>
<body class="wy-body-for-nav" date="2025-03-27">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="https://postgrest.postgresql.ac.cn/en/v12/index.html" class="icon icon-home">
PostgREST 12.2
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="https://postgrest.postgresql.ac.cn/en/v12/search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs">
<input type="hidden" name="check_keywords" value="yes">
<input type="hidden" name="area" value="default">
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">教程</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/tutorials/tut0.html">教程 0 - 启动运行</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/tutorials/tut1.html">教程 1 - 金钥匙</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">参考</span></p>
<ul class="current" aria-expanded="true">
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/auth.html">身份验证</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api.html">API</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/cli.html">CLI</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/transactions.html">事务</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/connection_pool.html">连接池</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/schema_cache.html">模式缓存</a></li>
<li class="toctree-l1 current" aria-expanded="true"><a class="reference internal current" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#" aria-expanded="true"><button class="toctree-expand" title="Open/close menu"></button>错误</a><ul>
<li class="toctree-l2"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#errors-from-postgresql"><button class="toctree-expand" title="Open/close menu"></button>来自 PostgreSQL 的错误</a><ul>
<li class="toctree-l3"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#http-status-codes">HTTP 状态码</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#errors-from-postgrest"><button class="toctree-expand" title="Open/close menu"></button>来自 PostgREST 的错误</a><ul>
<li class="toctree-l3"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#postgrest-error-codes"><button class="toctree-expand" title="Open/close menu"></button>PostgREST 错误代码</a><ul>
<li class="toctree-l4"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-0-connection">组 0 - 连接</a></li>
<li class="toctree-l4"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-1-api-request">组 1 - API 请求</a></li>
<li class="toctree-l4"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-2-schema-cache">组 2 - 模式缓存</a></li>
<li class="toctree-l4"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-3-jwt">组 3 - JWT</a></li>
<li class="toctree-l4"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-x-internal">组 X - 内部</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#custom-errors"><button class="toctree-expand" title="Open/close menu"></button>自定义错误</a><ul>
<li class="toctree-l3"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#raise-errors-with-http-status-codes">使用 HTTP 状态码 RAISE 错误</a></li>
<li class="toctree-l3"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#add-http-headers-with-raise">使用 RAISE 添加 HTTP 头</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/configuration.html">配置</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/observability.html">可观测性</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/admin_server.html">管理服务器</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/listener.html">监听器</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">解释</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/explanations/architecture.html">架构</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/explanations/db_authz.html">数据库授权</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/explanations/install.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/explanations/nginx.html">Nginx</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/explanations/schema_isolation.html">模式隔离</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">操作指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/how-tos/sql-user-management.html">SQL 用户管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/how-tos/sql-user-management-using-postgres-users-and-passwords.html">使用 postgres 的用户和密码进行 SQL 用户管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/how-tos/working-with-postgresql-data-types.html">使用 PostgreSQL 数据类型</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/how-tos/create-soap-endpoint.html">创建 SOAP 端点</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/how-tos/providing-html-content-using-htmx.html">使用 Htmx 提供 HTML 内容</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/how-tos/providing-images-for-img.html"><code class="docutils literal notranslate"><span class="pre">&lt;img&gt;</span></code> 提供图像</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">集成</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/integrations/greenplum.html">Greenplum</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/integrations/jwt_gen.html">外部 JWT 生成</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/integrations/pg-safeupdate.html">pg-safeupdate</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/integrations/systemd.html">systemd</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">生态系统</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/ecosystem.html">社区教程</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/ecosystem.html#templates">模板</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/ecosystem.html#example-apps">示例应用程序</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/ecosystem.html#devops">DevOps</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/ecosystem.html#external-notification">外部通知</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/ecosystem.html#extensions">扩展</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/ecosystem.html#client-side-libraries">客户端库</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i> <a href="https://postgrest.postgresql.ac.cn/en/v12/index.html">PostgREST 12.2</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="https://postgrest.postgresql.ac.cn/en/v12/index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">错误</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/postgrest/postgrest/blob/v12/docs/references/errors.rst" class="fa fa-github"> 在 GitHub 上编辑</a>
</li>
</ul>
<hr>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="errors">
<span id="error-source"></span><h1>错误<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#errors" title="Link to this heading"></a></h1>
<p>PostgREST 错误消息遵循 PostgreSQL 错误结构。它包括 <code class="docutils literal notranslate"><span class="pre">MESSAGE</span></code><code class="docutils literal notranslate"><span class="pre">DETAIL</span></code><code class="docutils literal notranslate"><span class="pre">HINT</span></code><code class="docutils literal notranslate"><span class="pre">ERRCODE</span></code>,并将向响应添加 HTTP 状态码。</p>
<section id="errors-from-postgresql">
<h2>来自 PostgreSQL 的错误<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#errors-from-postgresql" title="Link to this heading"></a></h2>
<p>PostgREST 将转发来自 PostgreSQL 的错误。例如,在约束失败时</p>
<div class="highlight-http notranslate"><div class="highlight"><pre id="codecell0"><span></span><span class="nf">POST</span> <span class="nn">/projects</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell0">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<div class="highlight-http notranslate"><div class="highlight"><pre id="codecell1"><span></span><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">400</span> <span class="ne">Bad Request</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json; charset=utf-8</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell1">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<div class="highlight-json notranslate"><div class="highlight"><pre id="codecell2"><span></span><span class="p">{</span>
<span class="w"> </span><span class="nt">"code"</span><span class="p">:</span><span class="w"> </span><span class="s2">"23502"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"details"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Failing row contains (null, foo, null)."</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"hint"</span><span class="p">:</span><span class="w"> </span><span class="kc">null</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"null value in column \"id\" of relation \"projects\" violates not-null constraint"</span>
<span class="p">}</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell2">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<section id="http-status-codes">
<span id="status-codes"></span><h3>HTTP 状态码<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#http-status-codes" title="Link to this heading"></a></h3>
<p>PostgREST 将 <a class="reference external" href="https://postgresql.ac.cn/docs/current/errcodes-appendix.html">PostgreSQL 错误代码</a> 转换为 HTTP 状态,如下所示</p>
<div class="wy-table-responsive"><table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>PostgreSQL 错误代码</p></th>
<th class="head"><p>HTTP 状态</p></th>
<th class="head"><p>错误描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>08*</p></td>
<td><p>503</p></td>
<td><p>pg 连接错误</p></td>
</tr>
<tr class="row-odd"><td><p>09*</p></td>
<td><p>500</p></td>
<td><p>触发操作异常</p></td>
</tr>
<tr class="row-even"><td><p>0L*</p></td>
<td><p>403</p></td>
<td><p>无效授予者</p></td>
</tr>
<tr class="row-odd"><td><p>0P*</p></td>
<td><p>403</p></td>
<td><p>无效角色规范</p></td>
</tr>
<tr class="row-even"><td><p>23503</p></td>
<td><p>409</p></td>
<td><p>外键冲突</p></td>
</tr>
<tr class="row-odd"><td><p>23505</p></td>
<td><p>409</p></td>
<td><p>唯一性冲突</p></td>
</tr>
<tr class="row-even"><td><p>25006</p></td>
<td><p>405</p></td>
<td><p>只读 SQL 事务</p></td>
</tr>
<tr class="row-odd"><td><p>25*</p></td>
<td><p>500</p></td>
<td><p>无效的事务状态</p></td>
</tr>
<tr class="row-even"><td><p>28*</p></td>
<td><p>403</p></td>
<td><p>无效的授权规范</p></td>
</tr>
<tr class="row-odd"><td><p>2D*</p></td>
<td><p>500</p></td>
<td><p>无效的事务终止</p></td>
</tr>
<tr class="row-even"><td><p>38*</p></td>
<td><p>500</p></td>
<td><p>外部例程异常</p></td>
</tr>
<tr class="row-odd"><td><p>39*</p></td>
<td><p>500</p></td>
<td><p>外部例程调用</p></td>
</tr>
<tr class="row-even"><td><p>3B*</p></td>
<td><p>500</p></td>
<td><p>保存点异常</p></td>
</tr>
<tr class="row-odd"><td><p>40*</p></td>
<td><p>500</p></td>
<td><p>事务回滚</p></td>
</tr>
<tr class="row-even"><td><p>53400</p></td>
<td><p>500</p></td>
<td><p>配置限制超出</p></td>
</tr>
<tr class="row-odd"><td><p>53*</p></td>
<td><p>503</p></td>
<td><p>资源不足</p></td>
</tr>
<tr class="row-even"><td><p>54*</p></td>
<td><p>500</p></td>
<td><p>过于复杂</p></td>
</tr>
<tr class="row-odd"><td><p>55*</p></td>
<td><p>500</p></td>
<td><p>对象不在先决条件状态</p></td>
</tr>
<tr class="row-even"><td><p>57*</p></td>
<td><p>500</p></td>
<td><p>操作员干预</p></td>
</tr>
<tr class="row-odd"><td><p>58*</p></td>
<td><p>500</p></td>
<td><p>系统错误</p></td>
</tr>
<tr class="row-even"><td><p>F0*</p></td>
<td><p>500</p></td>
<td><p>配置文件错误</p></td>
</tr>
<tr class="row-odd"><td><p>HV*</p></td>
<td><p>500</p></td>
<td><p>外部数据包装器错误</p></td>
</tr>
<tr class="row-even"><td><p>P0001</p></td>
<td><p>400</p></td>
<td><p>“raise”的默认代码</p></td>
</tr>
<tr class="row-odd"><td><p>P0*</p></td>
<td><p>500</p></td>
<td><p>PL/pgSQL 错误</p></td>
</tr>
<tr class="row-even"><td><p>XX*</p></td>
<td><p>500</p></td>
<td><p>内部错误</p></td>
</tr>
<tr class="row-odd"><td><p>42883</p></td>
<td><p>404</p></td>
<td><p>未定义函数</p></td>
</tr>
<tr class="row-even"><td><p>42P01</p></td>
<td><p>404</p></td>
<td><p>未定义表</p></td>
</tr>
<tr class="row-odd"><td><p>42P17</p></td>
<td><p>500</p></td>
<td><p>无限递归</p></td>
</tr>
<tr class="row-even"><td><p>42501</p></td>
<td><div class="line-block">
<div class="line">如果已认证,则返回 403</div>
<div class="line">否则返回 401</div>
</div>
</td>
<td><p>权限不足</p></td>
</tr>
<tr class="row-odd"><td><p>其他</p></td>
<td><p>400</p></td>
<td></td>
</tr>
</tbody>
</table></div>
</section>
</section>
<section id="errors-from-postgrest">
<h2>来自 PostgREST 的错误<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#errors-from-postgrest" title="Link to this heading"></a></h2>
<p>来自 PostgREST 本身的错误保持相同的结构,但在 <code class="docutils literal notranslate"><span class="pre">code</span></code> 字段中使用 <code class="docutils literal notranslate"><span class="pre">PGRST</span></code> 前缀。例如,当查询在 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/schema_cache.html"><span class="doc">schema 缓存</span></a> 中不存在的函数时</p>
<div class="highlight-http notranslate"><div class="highlight"><pre id="codecell3"><span></span><span class="nf">POST</span> <span class="nn">/rpc/nonexistent_function</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell3">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<div class="highlight-http notranslate"><div class="highlight"><pre id="codecell4"><span></span><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">404</span> <span class="ne">Not Found</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json; charset=utf-8</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell4">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<div class="highlight-json notranslate"><div class="highlight"><pre id="codecell5"><span></span><span class="p">{</span>
<span class="w"> </span><span class="nt">"hint"</span><span class="p">:</span><span class="w"> </span><span class="s2">"..."</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"details"</span><span class="p">:</span><span class="w"> </span><span class="kc">null</span>
<span class="w"> </span><span class="nt">"code"</span><span class="p">:</span><span class="w"> </span><span class="s2">"PGRST202"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Could not find the api.nonexistent_function() function in the schema cache"</span>
<span class="p">}</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell5">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<section id="postgrest-error-codes">
<span id="pgrst-errors"></span><h3>PostgREST 错误代码<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#postgrest-error-codes" title="Link to this heading"></a></h3>
<p>PostgREST 错误代码的格式为 <code class="docutils literal notranslate"><span class="pre">PGRSTgxx</span></code></p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">PGRST</span></code> 是区分错误与 PostgreSQL 错误的前缀。</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">g</span></code> 是错误组</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">xx</span></code> 是组中的错误标识符。</p></li>
</ul>
<section id="group-0-connection">
<span id="pgrst0"></span><h4>组 0 - 连接<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-0-connection" title="Link to this heading"></a></h4>
<p>与数据库的连接相关。</p>
<div class="wy-table-responsive"><table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>代码</p></th>
<th class="head"><p>HTTP 状态</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p id="pgrst000">PGRST000</p>
</td>
<td><p>503</p></td>
<td><p>由于 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/configuration.html#db-uri"><span class="std std-ref">db-uri</span></a> 不正确或 PostgreSQL 服务未运行,无法连接到数据库。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst001">PGRST001</p>
</td>
<td><p>503</p></td>
<td><p>由于内部错误,无法连接到数据库。</p></td>
</tr>
<tr class="row-even"><td><p id="pgrst002">PGRST002</p>
</td>
<td><p>503</p></td>
<td><p>在构建 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/schema_cache.html"><span class="doc">Schema Cache</span></a> 时无法连接到数据库,因为 PostgreSQL 服务未运行。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst003">PGRST003</p>
</td>
<td><p>504</p></td>
<td><p>请求在等待连接池可用时超时。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/configuration.html#db-pool-acquisition-timeout"><span class="std std-ref">db-pool-acquisition-timeout</span></a></p></td>
</tr>
</tbody>
</table></div>
</section>
<section id="group-1-api-request">
<span id="pgrst1"></span><h4>组 1 - API 请求<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-1-api-request" title="Link to this heading"></a></h4>
<p>与 HTTP 请求元素相关。</p>
<div class="wy-table-responsive"><table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>代码</p></th>
<th class="head"><p>HTTP 状态</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p id="pgrst100">PGRST100</p>
</td>
<td><p>400</p></td>
<td><p>查询字符串参数解析错误。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#h-filter"><span class="std std-ref">水平过滤</span></a><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#operators"><span class="std std-ref">运算符</span></a><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#ordering"><span class="std std-ref">排序</span></a></p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst101">PGRST101</p>
</td>
<td><p>405</p></td>
<td><p>对于 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/functions.html#functions"><span class="std std-ref">函数</span></a>,只允许使用 <code class="docutils literal notranslate"><span class="pre">GET</span></code><code class="docutils literal notranslate"><span class="pre">POST</span></code> 动词。任何其他动词都会抛出此错误。</p></td>
</tr>
<tr class="row-even"><td><p id="pgrst102">PGRST102</p>
</td>
<td><p>400</p></td>
<td><p>发送了无效的请求主体(例如空主体或格式错误的 JSON)。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst103">PGRST103</p>
</td>
<td><p>416</p></td>
<td><p><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/pagination_count.html#limits"><span class="std std-ref">限制和分页</span></a> 指定了无效的范围。</p></td>
</tr>
<tr class="row-even"><td><p id="pgrst105">PGRST105</p>
</td>
<td><p>405</p></td>
<td><p>执行了无效的 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#upsert-put"><span class="std std-ref">PUT</span></a> 请求。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst106">PGRST106</p>
</td>
<td><p>406</p></td>
<td><p><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/schemas.html#multiple-schemas"><span class="std std-ref">切换模式</span></a> 时指定的模式不存在于 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/configuration.html#db-schemas"><span class="std std-ref">db-schemas</span></a> 配置变量中。</p></td>
</tr>
<tr class="row-even"><td><p id="pgrst107">PGRST107</p>
</td>
<td><p>415</p></td>
<td><p>请求中发送的 <code class="docutils literal notranslate"><span class="pre">Content-Type</span></code> 无效。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst108">PGRST108</p>
</td>
<td><p>400</p></td>
<td><p>过滤器应用于未在查询字符串的 <code class="docutils literal notranslate"><span class="pre">select</span></code> 部分中指定的嵌入式资源。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/resource_embedding.html#embed-filters"><span class="std std-ref">嵌入式过滤器</span></a></p></td>
</tr>
<tr class="row-even"><td><p id="pgrst109">PGRST109</p>
</td>
<td><p>400</p></td>
<td><p>使用限制来限制删除或更新必须包含唯一列的排序。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#limited-update-delete"><span class="std std-ref">限制更新/删除</span></a></p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst110">PGRST110</p>
</td>
<td><p>400</p></td>
<td><p>当使用限制来限制删除或更新时,修改的行数超过限制中指定的最大值。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#limited-update-delete"><span class="std std-ref">限制更新/删除</span></a></p></td>
</tr>
<tr class="row-even"><td><p id="pgrst111">PGRST111</p>
</td>
<td><p>500</p></td>
<td><p>设置了无效的 <code class="docutils literal notranslate"><span class="pre">response.headers</span></code>。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/transactions.html#guc-resp-hdrs"><span class="std std-ref">响应头</span></a></p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst112">PGRST112</p>
</td>
<td><p>500</p></td>
<td><p>状态代码必须是正整数。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/transactions.html#guc-resp-status"><span class="std std-ref">响应状态代码</span></a></p></td>
</tr>
<tr class="row-even"><td><p id="pgrst114">PGRST114</p>
</td>
<td><p>400</p></td>
<td><p>对于使用 PUT 的 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#upsert-put"><span class="std std-ref">UPSERT</span></a>,当使用 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/pagination_count.html#limits"><span class="std std-ref">限制和偏移量</span></a> 时。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst115">PGRST115</p>
</td>
<td><p>400</p></td>
<td><p>对于使用 PUT 的 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#upsert-put"><span class="std std-ref">UPSERT</span></a>,当查询字符串中的主键与主体中的主键不同时。</p></td>
</tr>
<tr class="row-even"><td><p id="pgrst116">PGRST116</p>
</td>
<td><p>406</p></td>
<td><p>在请求单个响应时,返回了多个或没有项目。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/resource_representation.html#singular-plural"><span class="std std-ref">单数或复数</span></a></p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst117">PGRST117</p>
</td>
<td><p>405</p></td>
<td><p>请求中使用的 HTTP 动词不受支持。</p></td>
</tr>
<tr class="row-even"><td><p id="pgrst118">PGRST118</p>
</td>
<td><p>400</p></td>
<td><p>无法使用相关表对结果进行排序,因为它们之间没有多对一或一对一关系。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst119">PGRST119</p>
</td>
<td><p>400</p></td>
<td><p>无法在相关表上使用扩展运算符,因为它们之间没有多对一或一对一关系。</p></td>
</tr>
<tr class="row-even"><td><p id="pgrst120">PGRST120</p>
</td>
<td><p>400</p></td>
<td><p>嵌入式资源只能使用 <code class="docutils literal notranslate"><span class="pre">is.null</span></code><code class="docutils literal notranslate"><span class="pre">not.is.null</span></code> <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#operators"><span class="std std-ref">运算符</span></a> 进行过滤。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst121">PGRST121</p>
</td>
<td><p>500</p></td>
<td><p>PostgREST 无法解析 RAISE <code class="docutils literal notranslate"><span class="pre">PGRST</span></code> 错误中的 JSON 对象。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#raise-headers"><span class="std std-ref">raise 标头</span></a></p></td>
</tr>
<tr class="row-even"><td><p id="pgrst122">PGRST122</p>
</td>
<td><p>400</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">Prefer</span></code> 标头中发现无效的偏好设置,其中 <code class="docutils literal notranslate"><span class="pre">Prefer:</span> <span class="pre">handling=strict</span></code>。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/preferences.html#prefer-handling"><span class="std std-ref">严格或宽松处理</span></a></p></td>
</tr>
</tbody>
</table></div>
</section>
<section id="group-2-schema-cache">
<span id="pgrst2"></span><h4>第 2 组 - 架构缓存<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-2-schema-cache" title="Link to this heading"></a></h4>
<p><a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/schema_cache.html#schema-cache"><span class="std std-ref">架构缓存</span></a> 相关。大多数情况下,这些错误可以通过 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/schema_cache.html#schema-reloading"><span class="std std-ref">架构缓存重新加载</span></a> 解决。</p>
<div class="wy-table-responsive"><table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>代码</p></th>
<th class="head"><p>HTTP 状态</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p id="pgrst200">PGRST200</p>
</td>
<td><p>400</p></td>
<td><p>由过时的外键关系引起,否则任何嵌入式资源或关系本身可能不存在于数据库中。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst201">PGRST201</p>
</td>
<td><p>300</p></td>
<td><p>发出了不明确的嵌入请求。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/resource_embedding.html#complex-rels"><span class="std std-ref">多个外键关系上的外键连接</span></a></p></td>
</tr>
<tr class="row-even"><td><p id="pgrst202">PGRST202</p>
</td>
<td><p>404</p></td>
<td><p>由过时的函数签名引起,否则该函数可能不存在于数据库中。</p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst203">PGRST203</p>
</td>
<td><p>300</p></td>
<td><p>由于请求具有相同参数名称但类型不同的重载函数,或使用 <code class="docutils literal notranslate"><span class="pre">POST</span></code> 动词请求具有 <code class="docutils literal notranslate"><span class="pre">JSON</span></code><code class="docutils literal notranslate"><span class="pre">JSONB</span></code> 类型未命名参数的重载函数而导致。解决方法是重命名函数或添加/修改参数名称。</p></td>
</tr>
<tr class="row-even"><td><p id="pgrst204">PGRST204</p>
</td>
<td><p>400</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">columns</span></code> 查询参数中指定的 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/tables_views.html#specify-columns"><span class="std std-ref"></span></a> 未找到时导致。</p></td>
</tr>
</tbody>
</table></div>
</section>
<section id="group-3-jwt">
<span id="pgrst3"></span><h4>第 3 组 - JWT<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-3-jwt" title="Link to this heading"></a></h4>
<p>与使用 JWT 进行身份验证过程相关。您可以参考 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/tutorials/tut1.html#tut1"><span class="std std-ref">教程 1 - 金钥匙</span></a> 获取有关如何实现身份验证的示例,以及 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/auth.html"><span class="doc">身份验证页面</span></a> 获取有关此过程的更多信息。</p>
<div class="wy-table-responsive"><table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>代码</p></th>
<th class="head"><p>HTTP 状态</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p id="pgrst300">PGRST300</p>
</td>
<td><p>500</p></td>
<td><p>配置中缺少 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/configuration.html#jwt-secret"><span class="std std-ref">JWT 密钥</span></a></p></td>
</tr>
<tr class="row-odd"><td><p id="pgrst301">PGRST301</p>
</td>
<td><p>401</p></td>
<td><p>与 JWT 验证相关的任何错误,这意味着提供的 JWT 在某种程度上无效。</p></td>
</tr>
<tr class="row-even"><td><p id="pgrst302">PGRST302</p>
</td>
<td><p>401</p></td>
<td><p>尝试在 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/configuration.html#db-anon-role"><span class="std std-ref">db-anon-role</span></a> 中未设置匿名角色的情况下,在未进行 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/auth.html#client-auth"><span class="std std-ref">身份验证</span></a> 的情况下进行请求。</p></td>
</tr>
</tbody>
</table></div>
</section>
<section id="group-x-internal">
<span id="pgrst-x"></span><h4>第 X 组 - 内部<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#group-x-internal" title="Link to this heading"></a></h4>
<p>内部错误。如果您遇到任何这些错误,您可能遇到了 PostgREST 错误,请 <a class="reference external" href="https://github.com/PostgREST/postgrest/issues">打开一个问题</a>,我们将很乐意修复它。</p>
<div class="wy-table-responsive"><table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>代码</p></th>
<th class="head"><p>HTTP 状态</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p id="pgrstx00">PGRSTX00</p>
</td>
<td><p>500</p></td>
<td><p>与用于连接到数据库的库相关的内部错误。</p></td>
</tr>
</tbody>
</table></div>
</section>
</section>
</section>
<section id="custom-errors">
<h2>自定义错误<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#custom-errors" title="Link to this heading"></a></h2>
<p>您可以使用函数上的 <a class="reference external" href="https://postgresql.ac.cn/docs/current/plpgsql-errors-and-messages.html#PLPGSQL-STATEMENTS-RAISE">RAISE 语句</a> 自定义错误。</p>
<section id="raise-errors-with-http-status-codes">
<span id="raise-error"></span><h3>使用 HTTP 状态代码引发错误<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#raise-errors-with-http-status-codes" title="Link to this heading"></a></h3>
<p>可以通过在 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/api/functions.html#functions"><span class="std std-ref">函数</span></a> 中引发 SQL 异常来实现自定义状态代码。例如,以下是一个始终以错误响应的函数</p>
<div class="highlight-postgres notranslate"><div class="highlight"><pre id="codecell6"><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">OR</span><span class="w"> </span><span class="k">REPLACE</span><span class="w"> </span><span class="k">FUNCTION</span><span class="w"> </span><span class="n">just_fail</span><span class="p">()</span><span class="w"> </span><span class="k">RETURNS</span><span class="w"> </span><span class="nb">void</span>
<span class="w"> </span><span class="k">LANGUAGE</span><span class="w"> </span><span class="n">plpgsql</span>
<span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="s">$$</span>
<span class="k">BEGIN</span>
<span class="w"> </span><span class="k">RAISE</span><span class="w"> </span><span class="k">EXCEPTION</span><span class="w"> </span><span class="s1">'I refuse!'</span>
<span class="w"> </span><span class="k">USING</span><span class="w"> </span><span class="n">DETAIL</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Pretty simple'</span><span class="p">,</span>
<span class="w"> </span><span class="n">HINT</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'There is nothing you can do.'</span><span class="p">;</span>
<span class="k">END</span>
<span class="s">$$</span><span class="p">;</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell6">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<p>调用函数返回 HTTP 400,并带有主体</p>
<div class="highlight-json notranslate"><div class="highlight"><pre id="codecell7"><span></span><span class="p">{</span>
<span class="w"> </span><span class="nt">"message"</span><span class="p">:</span><span class="s2">"I refuse!"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"details"</span><span class="p">:</span><span class="s2">"Pretty simple"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"hint"</span><span class="p">:</span><span class="s2">"There is nothing you can do."</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"code"</span><span class="p">:</span><span class="s2">"P0001"</span>
<span class="p">}</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell7">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<p>自定义 HTTP 状态码的一种方法是根据 PostgREST <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#status-codes"><span class="std std-ref">错误到状态码映射</span></a> 抛出特定异常。例如,<code class="code docutils literal notranslate"><span class="pre">RAISE</span> <span class="pre">insufficient_privilege</span></code> 将根据情况返回 HTTP 401/403。</p>
<p>为了更精确地控制 HTTP 状态码,请抛出 <code class="docutils literal notranslate"><span class="pre">PTxyz</span></code> 类型的异常。例如,要返回 HTTP 402,请抛出 <code class="docutils literal notranslate"><span class="pre">PT402</span></code></p>
<div class="highlight-postgres notranslate"><div class="highlight"><pre id="codecell8"><span></span><span class="n">RAISE</span><span class="w"> </span><span class="n">sqlstate</span><span class="w"> </span><span class="s1">'PT402'</span><span class="w"> </span><span class="k">using</span>
<span class="w"> </span><span class="n">message</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Payment Required'</span><span class="p">,</span>
<span class="w"> </span><span class="n">detail</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Quota exceeded'</span><span class="p">,</span>
<span class="w"> </span><span class="n">hint</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Upgrade your plan'</span><span class="p">;</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell8">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<p>返回值</p>
<div class="highlight-http notranslate"><div class="highlight"><pre id="codecell9"><span></span><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">402</span> <span class="ne">Payment Required</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json; charset=utf-8</span>
<span class="p">{</span>
<span class="w"> </span><span class="nt">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Payment Required"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"details"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Quota exceeded"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"hint"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Upgrade your plan"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"code"</span><span class="p">:</span><span class="w"> </span><span class="s2">"PT402"</span>
<span class="p">}</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell9">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
</section>
<section id="add-http-headers-with-raise">
<span id="raise-headers"></span><h3>使用 RAISE 添加 HTTP 头<a class="headerlink" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#add-http-headers-with-raise" title="Link to this heading"></a></h3>
<p>为了完全控制头信息和状态,您可以抛出 <code class="docutils literal notranslate"><span class="pre">PGRST</span></code> SQLSTATE 错误。您可以通过在 PostgreSQL 错误消息字段中添加 <code class="docutils literal notranslate"><span class="pre">code</span></code><code class="docutils literal notranslate"><span class="pre">message</span></code><code class="docutils literal notranslate"><span class="pre">detail</span></code><code class="docutils literal notranslate"><span class="pre">hint</span></code> 作为 JSON 对象来实现。这里,<code class="docutils literal notranslate"><span class="pre">details</span></code><code class="docutils literal notranslate"><span class="pre">hint</span></code> 是可选的。类似地,<code class="docutils literal notranslate"><span class="pre">status</span></code><code class="docutils literal notranslate"><span class="pre">headers</span></code> 必须作为 JSON 对象添加到 SQL 错误详细信息字段中。例如</p>
<div class="highlight-postgres notranslate"><div class="highlight"><pre id="codecell10"><span></span><span class="n">RAISE</span><span class="w"> </span><span class="n">sqlstate</span><span class="w"> </span><span class="s1">'PGRST'</span><span class="w"> </span><span class="k">USING</span>
<span class="w"> </span><span class="n">message</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'{"code":"123","message":"Payment Required","details":"Quota exceeded","hint":"Upgrade your plan"}'</span><span class="p">,</span>
<span class="w"> </span><span class="n">detail</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'{"status":402,"headers":{"X-Powered-By":"Nerd Rage"}}'</span><span class="p">;</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell10">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<p>返回值</p>
<div class="highlight-http notranslate"><div class="highlight"><pre id="codecell11"><span></span><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">402</span> <span class="ne">Payment Required</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json; charset=utf-8</span>
<span class="na">X-Powered-By</span><span class="o">:</span> <span class="l">Nerd Rage</span>
<span class="p">{</span>
<span class="w"> </span><span class="nt">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Payment Required"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"details"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Quota exceeded"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"hint"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Upgrade your plan"</span><span class="p">,</span>
<span class="w"> </span><span class="nt">"code"</span><span class="p">:</span><span class="w"> </span><span class="s2">"123"</span>
<span class="p">}</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell11">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<p>对于非标准 HTTP 状态,您可以选择添加 <code class="docutils literal notranslate"><span class="pre">status_text</span></code> 来描述状态码。对于状态码 <code class="docutils literal notranslate"><span class="pre">419</span></code>,详细信息字段可能如下所示</p>
<div class="highlight-postgres notranslate"><div class="highlight"><pre id="codecell12"><span></span><span class="n">detail</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'{"status":419,"status_text":"Page Expired","headers":{"X-Powered-By":"Nerd Rage"}}'</span><span class="p">;</span>
</pre><button class="copybtn o-tooltip--left" data-tooltip="Copy" data-clipboard-target="#codecell12">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round">
<title>Copy to clipboard</title>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<rect x="8" y="8" width="12" height="12" rx="2"></rect>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>
</button></div>
</div>
<p>如果 PostgREST 无法解析 JSON 对象 <code class="docutils literal notranslate"><span class="pre">message</span></code><code class="docutils literal notranslate"><span class="pre">detail</span></code>,它将抛出 <code class="docutils literal notranslate"><span class="pre">PGRST121</span></code> 错误。请参阅 <a class="reference internal" href="https://postgrest.postgresql.ac.cn/en/v12/references/errors.html#pgrst1"><span class="std std-ref">PostgREST 错误</span></a></p>
</section>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="https://postgrest.postgresql.ac.cn/en/v12/references/schema_cache.html" class="btn btn-neutral float-left" title="Schema Cache" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> 上一页</a> <a href="https://postgrest.postgresql.ac.cn/en/v12/references/configuration.html" class="btn btn-neutral float-right" title="Configuration" accesskey="n" rel="next">下一页 <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr>
<div role="contentinfo">
<p>© Copyright 2017, Joe Nelson, Steve Chavez. <span class="commit">Revision <code>94f05483</code>. </span></p>
</div>
使用 <a href="https://sphinx-doc.cn/">Sphinx</a><a href="https://github.com/readthedocs/sphinx_rtd_theme">主题</a>(由 <a href="https://readthedocs.org/">Read the Docs</a> 提供)构建。
<a href="https://github.com/MrDogeBro/sphinx_rtd_dark_mode">Dark theme</a> provided by <a href="http://mrdogebro.com/">MrDogeBro</a>.</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="Versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span class="fa fa-book"> Read the Docs</span> v: v12 <span class="fa fa-caret-down"></span>
</span>
<div class="rst-other-versions">
<dl>
<dt>版本</dt>
<dd><a href="https://postgrest.postgresql.ac.cn/en/latest/">最新</a></dd>
<dd><a href="https://postgrest.postgresql.ac.cn/en/stable/">稳定版</a></dd>
<dd><a href="https://postgrest.postgresql.ac.cn/en/v12/">v12</a></dd>
<dd><a href="https://postgrest.postgresql.ac.cn/en/v11/">v11</a></dd>
<dd><a href="https://postgrest.postgresql.ac.cn/en/v10/">v10</a></dd>
</dl>
<dl>
<dt>下载</dt>
</dl>
<dl>
<dt>在 Read the Docs 上</dt>
<dd>
<a href="https://readthedocs.org/projects/postgrest/?fromdocs=postgrest">项目主页</a>
</dd>
<dd>
<a href="https://readthedocs.org/builds/postgrest/?fromdocs=postgrest">构建</a>
</dd>
</dl>
</div>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
<button class="theme-switcher" id="themeSwitcher"><i id="themeMoon" class="fa fa-moon-o"></i><i id="themeSun" class="fa fa-sun-o" style="display: none;"></i></button><ins class="adsbygoogle adsbygoogle-noablate" data-adsbygoogle-status="done" style="display: none !important;" data-ad-status="unfilled"><div id="aswift_0_host" style="border: none; height: 0px; width: 0px; margin: 0px; padding: 0px; position: relative; visibility: visible; background-color: transparent; display: inline-block;"><iframe id="aswift_0" name="aswift_0" browsingtopics="true" style="left:0;position:absolute;top:0;border:0;width:undefinedpx;height:undefinedpx;" sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allow="attribution-reporting; run-ad-auction" src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/ads.html" data-google-container-id="a!1" tabindex="0" title="Advertisement" aria-label="Advertisement" data-load-complete="true"></iframe></div></ins><iframe name="googlefcPresent" style="display: none; width: 0px; height: 0px; border: none; z-index: -1000; left: -1000px; top: -1000px;" src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/saved_resource.html"></iframe><iframe src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/aframe.html" width="0" height="0" style="display: none;"></iframe></body><iframe id="google_esf" name="google_esf" src="./错误 — PostgREST 12.2 文档 - PostgREST 中文_files/zrt_lookup_fy2021.html" style="display: none;"></iframe></html>