For the SQL gurus out there

Поиск
Список
Период
Сортировка
От Uwe C. Schroeder
Тема For the SQL gurus out there
Дата
Msg-id 200712122155.05160.uwe@oss4u.com
обсуждение исходный текст
Ответы Re: For the SQL gurus out there  ("D. Dante Lorenso" <dante@lorenso.com>)
Re: For the SQL gurus out there  (Richard Broersma Jr <rabroersma@yahoo.com>)
Re: For the SQL gurus out there  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Re: For the SQL gurus out there  ("Uwe C. Schroeder" <uwe@oss4u.com>)
Список pgsql-general
Ok, something I've been toying around with for a while.
Here's the scenario:
Imagine a blogging app.
I have a table for blogs with a blog_id (primary key)
and a table blog_comments also with a comment_id as primary key and a foreign
key holding the blog_id the post belongs to.
The comments table also has a field that holds a self-reference to comment id
for commments on comments (on comments) of a blog.

What I would like to do is to create a view that sucks the comments for a
given blog_id in the order they should be displayed (very commonly seen in
pretty much all blogging apps), i.e.

Blog
comment 1
  comment on comment 1
    comment on comment on comment 1
comment 2
etc.


Question is, is there a smart way I'm not able to figure out to create a
single query on the blog comment table that will return the comments in the
right order? Sure I could write a recursive method that assembles the data in
correct order, but I'd prefer to leave that to the database to handle in a
view.

The solution can be very postgresql specific, because I don't intend to run it
on any other db server.

Any ideas anyone?

THX

    UC

--
Open Source Solutions 4U, LLC    1618 Kelly St
Phone:  +1 707 568 3056        Santa Rosa, CA 95401
Cell:   +1 650 302 2405        United States
Fax:    +1 707 568 6416

В списке pgsql-general по дате отправления:

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: timestamp with time zone
Следующее
От: Tatsuo Ishii
Дата:
Сообщение: Re: timestamp with time zone