<small id='QjqJC'></small><noframes id='QjqJC'>

      <bdo id='QjqJC'></bdo><ul id='QjqJC'></ul>
    <tfoot id='QjqJC'></tfoot>
    1. <legend id='QjqJC'><style id='QjqJC'><dir id='QjqJC'><q id='QjqJC'></q></dir></style></legend>
    2. <i id='QjqJC'><tr id='QjqJC'><dt id='QjqJC'><q id='QjqJC'><span id='QjqJC'><b id='QjqJC'><form id='QjqJC'><ins id='QjqJC'></ins><ul id='QjqJC'></ul><sub id='QjqJC'></sub></form><legend id='QjqJC'></legend><bdo id='QjqJC'><pre id='QjqJC'><center id='QjqJC'></center></pre></bdo></b><th id='QjqJC'></th></span></q></dt></tr></i><div id='QjqJC'><tfoot id='QjqJC'></tfoot><dl id='QjqJC'><fieldset id='QjqJC'></fieldset></dl></div>
    3. 与 Oracle 的 CONNECT BY ... START WITH 等效的 PostgreSQL 语法是什么?

      What is the equivalent PostgreSQL syntax to Oracle#39;s CONNECT BY ... START WITH?(与 Oracle 的 CONNECT BY ... START WITH 等效的 PostgreSQL 语法是什么?)
      • <i id='0bmXS'><tr id='0bmXS'><dt id='0bmXS'><q id='0bmXS'><span id='0bmXS'><b id='0bmXS'><form id='0bmXS'><ins id='0bmXS'></ins><ul id='0bmXS'></ul><sub id='0bmXS'></sub></form><legend id='0bmXS'></legend><bdo id='0bmXS'><pre id='0bmXS'><center id='0bmXS'></center></pre></bdo></b><th id='0bmXS'></th></span></q></dt></tr></i><div id='0bmXS'><tfoot id='0bmXS'></tfoot><dl id='0bmXS'><fieldset id='0bmXS'></fieldset></dl></div>

            <bdo id='0bmXS'></bdo><ul id='0bmXS'></ul>

            <small id='0bmXS'></small><noframes id='0bmXS'>

              <tfoot id='0bmXS'></tfoot>
                <tbody id='0bmXS'></tbody>

            1. <legend id='0bmXS'><style id='0bmXS'><dir id='0bmXS'><q id='0bmXS'></q></dir></style></legend>

                本文介绍了与 Oracle 的 CONNECT BY ... START WITH 等效的 PostgreSQL 语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Oracle中,如果我有一个表定义为……

                In Oracle, if I have a table defined as …

                CREATE TABLE taxonomy
                    (
                    key NUMBER(11) NOT NULL CONSTRAINT taxPkey PRIMARY KEY,
                    value VARCHAR2(255),
                    taxHier NUMBER(11)
                    );
                ALTER TABLE
                    taxonomy
                ADD CONSTRAINT
                    taxTaxFkey
                FOREIGN KEY
                    (taxHier)
                REFERENCES
                    tax(key);
                

                有了这些值......

                With these values …

                key value   taxHier
                0   zero    null
                1   one     0
                2   two     0
                3   three   0
                4   four    1
                5   five    2
                6   six     2
                

                这个查询语法……

                SELECT
                     value
                FROM
                    taxonomy
                CONNECT BY
                    PRIOR key = taxHier
                START WITH
                    key = 0;
                

                会产生……

                zero
                one
                four
                two
                five
                six
                three
                

                这在 PostgreSQL 中是如何完成的?

                How is this done in PostgreSQL?

                推荐答案

                在 Postgres 中使用 RECURSIVE CTE:

                Use a RECURSIVE CTE in Postgres:

                WITH RECURSIVE cte AS (
                   SELECT key, value, 1 AS level
                   FROM   taxonomy
                   WHERE  key = 0
                
                   UNION  ALL
                   SELECT t.key, t.value, c.level + 1
                   FROM   cte      c
                   JOIN   taxonomy t ON t.taxHier = c.key
                   )
                SELECT value
                FROM   cte
                ORDER  BY level;
                

                我之前回答中的详细信息和文档链接:

                Details and links to documentation in my previous answer:

                • PostgreSQL 是否有像LEVEL"这样的伪列?在 Oracle 中?

                这篇关于与 Oracle 的 CONNECT BY ... START WITH 等效的 PostgreSQL 语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Oracle PL/SQL - Raise User-Defined Exception With Custom SQLERRM(Oracle PL/SQL - 使用自定义 SQLERRM 引发用户定义的异常)
                Oracle: is there a tool to trace queries, like Profiler for sql server?(Oracle:是否有跟踪查询的工具,例如用于 sql server 的 Profiler?)
                SELECT INTO using Oracle(使用 Oracle SELECT INTO)
                How to handle Day Light Saving in Oracle database(如何在 Oracle 数据库中处理夏令时)
                PL/SQL - Use quot;Listquot; Variable in Where In Clause(PL/SQL - 使用“列表Where In 子句中的变量)
                Oracle: Import CSV file(Oracle:导入 CSV 文件)
                <i id='NqjRg'><tr id='NqjRg'><dt id='NqjRg'><q id='NqjRg'><span id='NqjRg'><b id='NqjRg'><form id='NqjRg'><ins id='NqjRg'></ins><ul id='NqjRg'></ul><sub id='NqjRg'></sub></form><legend id='NqjRg'></legend><bdo id='NqjRg'><pre id='NqjRg'><center id='NqjRg'></center></pre></bdo></b><th id='NqjRg'></th></span></q></dt></tr></i><div id='NqjRg'><tfoot id='NqjRg'></tfoot><dl id='NqjRg'><fieldset id='NqjRg'></fieldset></dl></div>
                  <bdo id='NqjRg'></bdo><ul id='NqjRg'></ul>

                    <legend id='NqjRg'><style id='NqjRg'><dir id='NqjRg'><q id='NqjRg'></q></dir></style></legend>

                    <small id='NqjRg'></small><noframes id='NqjRg'>

                          <tbody id='NqjRg'></tbody>
                      • <tfoot id='NqjRg'></tfoot>