hierarchical-query

Oracle 10g Connect By Prior - Performance Issues

杀马特。学长 韩版系。学妹 提交于 2019-12-12 08:57:40
问题 I have the following SQL statement: SELECT CONNECT_BY_ROOT ANIMAL_ID "ORIGINAL_ANIMAL" , ANIMAL_ID, LINE_ID, SIRE_ANIMAL_ID, DAM_ANIMAL_ID, LEVEL -1 "LEVEL" FROM ANIMALS START WITH ANIMAL_ID IN( '2360000002558' ) CONNECT BY ((PRIOR SIRE_ANIMAL_ID = ANIMAL_ID and LEVEL < 5) OR (PRIOR DAM_ANIMAL_ID = ANIMAL_ID AND LEVEL < 5)) This in in a table with about 1.6 Million animals. Each record has Animal_Id, Sire_Animal_Id, and Dam_Animal_Id (Sire = Father, Dam = Mother). I use this sql to display

How to traverse a hierarchical tree-structure structure backwards using recursive queries

喜夏-厌秋 提交于 2019-12-09 04:39:37
问题 I'm using PostgreSQL 9.1 to query hierarchical tree-structured data, consisting of edges (or elements) with connections to nodes. The data are actually for stream networks, but I've abstracted the problem to simple data types. Consider the example tree table. Each edge has length and area attributes, which are used to determine some useful metrics from the network. CREATE TEMP TABLE tree ( edge text PRIMARY KEY, from_node integer UNIQUE NOT NULL, -- can also act as PK to_node integer

How do I query for all the nodes between two nodes in a tree?

耗尽温柔 提交于 2019-12-06 04:41:55
I have a hierarchical database strucutre, e.g. columns ID and PARENT_ID defined for each row, with the top level rows having a NULL PARENT_ID . I have all the relationships from this table flattened into another table, e.g. if there were three records in a single hierarchy of grandparent, parent, grandchild, there would be 3 records: **ANCESTOR, DESCENDANT** grantparent, parent grandparent, grandchild parent, grandchild Rather than execute a hierarchical query to determine that the grandchild is a descendant of the grandparent I can simply check for the existence of a (grandparent, grandchild)

Oracle 10g Connect By Prior - Performance Issues

橙三吉。 提交于 2019-12-04 12:12:10
I have the following SQL statement: SELECT CONNECT_BY_ROOT ANIMAL_ID "ORIGINAL_ANIMAL" , ANIMAL_ID, LINE_ID, SIRE_ANIMAL_ID, DAM_ANIMAL_ID, LEVEL -1 "LEVEL" FROM ANIMALS START WITH ANIMAL_ID IN( '2360000002558' ) CONNECT BY ((PRIOR SIRE_ANIMAL_ID = ANIMAL_ID and LEVEL < 5) OR (PRIOR DAM_ANIMAL_ID = ANIMAL_ID AND LEVEL < 5)) This in in a table with about 1.6 Million animals. Each record has Animal_Id, Sire_Animal_Id, and Dam_Animal_Id (Sire = Father, Dam = Mother). I use this sql to display the full animal pedigree. Results Will show Animal, 2 Parent, 4 GrandParents, etc. My issue is that this

How to traverse a hierarchical tree-structure structure backwards using recursive queries

左心房为你撑大大i 提交于 2019-12-03 01:57:49
I'm using PostgreSQL 9.1 to query hierarchical tree-structured data, consisting of edges (or elements) with connections to nodes. The data are actually for stream networks, but I've abstracted the problem to simple data types. Consider the example tree table. Each edge has length and area attributes, which are used to determine some useful metrics from the network. CREATE TEMP TABLE tree ( edge text PRIMARY KEY, from_node integer UNIQUE NOT NULL, -- can also act as PK to_node integer REFERENCES tree (from_node), mode character varying(5), -- redundant, but illustrative length numeric NOT NULL,

How to convert oracle hierarchical queries to postgresql?

馋奶兔 提交于 2019-12-02 00:50:23
问题 I want to convert below mentioned oracle hierarchical query to postgresql SELECT catalog_id, sub_tree_id FROM my_catalog CONNECT BY PRIOR catalog_id = sub_tree_id; I have tried using the following postgresql query but not getting the expected result WITH RECURSIVE q AS ( SELECT po.catalog_id,po.sub_tree_id FROM my_catalog po UNION ALL SELECT po.catalog_id,po.sub_tree_id FROM my_catalog po JOIN q ON q.catalog_id=po.sub_tree_id ) SELECT * FROM q; ORACLE OUTPUT(EXPECTED RESULT) POSTGRESQL OUTPUT

Does PostgreSQL have a pseudo-column like “LEVEL” in Oracle?

佐手、 提交于 2019-12-01 15:47:13
Does PostgreSQL have a pseudo-column like "LEVEL" in Oracle? If not, then how can we create a column similar to "LEVEL"? Erwin Brandstetter Postgres does not have hierarchical queries . No CONNECT BY , therefore also no LEVEL . The additional module tablefunc provides the function connectby() doing almost the same. See: What is the equivalent PostgreSQL syntax to Oracle's CONNECT BY ... START WITH? Or you can do similar things with a standard recursive CTE and a level column that's incremented with every recursion. This query in Oracle: SELECT employee_id, last_name, manager_id, LEVEL FROM

get ALL last level children (leafs) from a node (hierarhical queries Oracle 11G)

早过忘川 提交于 2019-12-01 09:25:18
I am trying and searching the way to get ALL last level children (leafs) from a node , in a hierchical query in Oracle 11g database. I have 2 tables: "Nodes" (A list of all nodes with their respective value), and "Relation" which specify father-child relation: --NODES-- ID_NODE - VALUE 1 3 2 6 3 9 4 2 5 4 6 5 7 2 8 7 9 8 10 1 --RELATION-- ID_FATHER - ID_CHILD 1 2 1 3 1 4 2 5 2 6 4 7 5 8 5 9 7 10 I have read about CONNECT_BY_ISLEAF which returns 1 if it is a leaf, but I cannot query CONNECT_BY_ISLEAF like the Oracle example, and I don´t get any result. Even though I don´t know exactly how to

get ALL last level children (leafs) from a node (hierarhical queries Oracle 11G)

孤街浪徒 提交于 2019-12-01 05:47:41
问题 I am trying and searching the way to get ALL last level children (leafs) from a node , in a hierchical query in Oracle 11g database. I have 2 tables: "Nodes" (A list of all nodes with their respective value), and "Relation" which specify father-child relation: --NODES-- ID_NODE - VALUE 1 3 2 6 3 9 4 2 5 4 6 5 7 2 8 7 9 8 10 1 --RELATION-- ID_FATHER - ID_CHILD 1 2 1 3 1 4 2 5 2 6 4 7 5 8 5 9 7 10 I have read about CONNECT_BY_ISLEAF which returns 1 if it is a leaf, but I cannot query CONNECT_BY

Cycle detection with recursive subquery factoring

眉间皱痕 提交于 2019-11-30 04:42:27
Oracle SQL can do hierarchical queries since v2, using their proprietary CONNECT BY syntax. In their latest 11g release 2, they added recursive subquery factoring, also known as the recursive with clause. This is the ANSI standard, and if I understand correctly, this one has been implemented by other RDBMS vendors as well. When comparing the connect-by with the recursive with, I noticed a difference in the result set when using cycle detection. The connect by results are more intuitive to me, so I'm wondering if Oracle's implementation contains a bug, or if this is standard ANSI and expected