pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedA SQL Training
3+ messages / 3 participants
[nested] [flat]
* A SQL Training
@ 2002-07-16 17:18 Devrim GUNDUZ <devrim@oper.metu.edu.tr>
0 siblings, 2 replies; 3+ messages in thread
From: Devrim GUNDUZ @ 2002-07-16 17:18 UTC (permalink / raw)
To: pgsql-sql
Hi,
Today, one of my teacher asked me a question for a practice... I could not
solve it :)
Here it comes:
We are given the name of the grandfather in a family. Let's call him A. A
has n sons, each son has children .
for example.
A -> Grandfather
/ \
/ \
B C
/\ / \ \
/ \ D E F
G H
...
We are given the data like ('A','B'),('C','D')...
Now, we do not know how many children are in the list. How could we list
this family tree in "tree" formt by only using SQL?
Best regards.
--
Devrim GUNDUZ
devrim@oper.metu.edu.tr
devrim.gunduz@linux.org.tr
Web : http://devrim.oper.metu.edu.tr
-------------------------------------
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: A SQL Training
@ 2002-07-16 18:07 Josh Berkus <josh@agliodbs.com>
parent: Devrim GUNDUZ <devrim@oper.metu.edu.tr>
1 sibling, 0 replies; 3+ messages in thread
From: Josh Berkus @ 2002-07-16 18:07 UTC (permalink / raw)
To: Devrim GUNDUZ <devrim@oper.metu.edu.tr>; pgsql-sql
Devrim,
> Today, one of my teacher asked me a question for a practice... I could not
> solve it :)
>
> Here it comes:
>
> We are given the name of the grandfather in a family. Let's call him A. A
> has n sons, each son has children .
etc.
In a month or so, I will be posting an article on advanced tree structure
(based on Joe Celko's work) in PostgreSQL.
Until then, buy a copy of SQL for Smarties, 2nd ed. by Joe Celko. He has two
chapters on tree structure.
--
-Josh Berkus
Aglio Database Solutions
San Francisco
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: A SQL Training
@ 2002-07-17 07:00 Achilleus Mantzios <achill@matrix.gatewaynet.com>
parent: Devrim GUNDUZ <devrim@oper.metu.edu.tr>
1 sibling, 0 replies; 3+ messages in thread
From: Achilleus Mantzios @ 2002-07-17 07:00 UTC (permalink / raw)
To: Devrim GUNDUZ <devrim@oper.metu.edu.tr>; +Cc: pgsql-sql
On Tue, 16 Jul 2002, Devrim GUNDUZ wrote:
You need to identify your problem: preorder traversal on a tree
using pointers for the fathers.
Then you have to prove (or prove the opposite) that SQL alone
is capable of expressing what you need.
BTW, Nested Sets are only good for "static" databases.
Pointers are good for intensively "dynamic" databases, but have some
performance problems (for instance traversing to the root).
A genealogical approach (just like Oleg's and Teodor's one in
contrib/tree) seems the most attractive.
Also you can have your own setup using postgresql arrays
(The arrays could contain the path of ids of the nodes from
the specific node to the root).
All these probably have little to do with your problem
(which is a computational theory problem), but maybe useful
in other cases.
>
> Hi,
>
> Today, one of my teacher asked me a question for a practice... I could not
> solve it :)
>
> Here it comes:
>
> We are given the name of the grandfather in a family. Let's call him A. A
> has n sons, each son has children .
>
> for example.
> A -> Grandfather
> / \
> / \
> B C
> /\ / \ \
> / \ D E F
> G H
> ...
>
> We are given the data like ('A','B'),('C','D')...
>
> Now, we do not know how many children are in the list. How could we list
> this family tree in "tree" formt by only using SQL?
>
> Best regards.
>
>
>
>
>
>
--
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
Nikis 4, Glyfada
Athens 16610
Greece
tel: +30-10-8981112
fax: +30-10-8981877
email: achill@matrix.gatewaynet.com
mantzios@softlab.ece.ntua.gr
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2002-07-17 07:00 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-07-16 17:18 A SQL Training Devrim GUNDUZ <devrim@oper.metu.edu.tr>
2002-07-16 18:07 ` Josh Berkus <josh@agliodbs.com>
2002-07-17 07:00 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox