Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

Postgre start with connect by prior

Postgre start with connect by prior 16.08.2012. u 18:16 · pre 173 meseca #1
Koji je najefikasniji/najjednostavniji/najbolji ekvivalent oraclovom upitu:

Code (sql):

SELECT id, parent, opis
  FROM tabela
START WITH id = 1
CONNECT BY prior id = parent;
 
Re: Postgre start with connect by prior 23.08.2012. u 15:23 · pre 173 meseca #2
To je neki rekurzivni upit?

nesto kao ovo (CTE) :

Code:

WITH RECURSIVE subtabela AS
(
    SELECT id, parent, opis FROM tabela WHERE id = 1

    UNION ALL

    SELECT t.id, t.parent, t.opis FROM tabela t
               INNER JOIN subtabela st ON t.parent = st.id
)
SELECT * FROM subtabela ;
Sviđa mi se1
Re: Postgre start with connect by prior 23.08.2012. u 16:09 · pre 173 meseca #3
Code:

CREATE OR REPLACE FUNCTION connectby(text, text, text, text, text, integer)
  RETURNS SETOF record AS
'$libdir/tablefunc', 'connectby_text_serial'
  LANGUAGE 'c' STABLE STRICT
  COST 1
  ROWS 1000;
ALTER FUNCTION connectby(text, text, text, text, text, integer) OWNER TO postgres;


Ne znam koju verziju PG koristis, ako je manja od 8.2 najverovatnije ce ti javljati gresku
na COST i ROWS, mozes da izbacis to.

Pozivas ovako:

Code:

SELECT ta.id,ta.parrent,ta.opis FROM tabela ta,
CONNECTBY('tabela', 'id','parrent', 'opis', '0',  0) as t(ide int, p_id int, lv int, pos int)
WHERE ta.id = ide

Potpis
"Ne menjaj nesto sto te sasvim dobro sluzi, ne trazi leba preko pogace" - Aleksandar Andrijevic
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme