Recursion in SQL

Поиск
Список
Период
Сортировка
От Zeb Fropiaz
Тема Recursion in SQL
Дата
Msg-id Uho29.3878$wh1.2446@news01.bloor.is.net.cable.rogers.com
обсуждение исходный текст
Список pgsql-general
I want to find if X is a friend of Y. But the frienship could be through a
chain of other friends as well. So I need to use recursion. I wrote the
following code similar to something I found at IBM's site
(ftp://ftp.software.ibm.com/ps/products/db2/info/vr6/htm/db2s0/db2s0503.htm#
Header_1031)

void find_friend() {

EXEC SQL BEGIN DECLARE SECTION;
       short Xsid;
       short Ysid;
       short count;
EXEC SQL END DECLARE SECTION;

printf("\nEnter first ID: ");
scanf("%hd", &Xsid);

printf("\nEnter second ID: ");
scanf("%hd", &Ysid);

       EXEC SQL WITH Friend (own_id, friend_id) AS
               ( SELECT own_id, friend_id
                 FROM c434h27.bond B
                 WHERE own_id = :Xsid
               UNION ALL
                 SELECT B2.own_id, B2.friend_id
                 FROM Friend B1, c434h27.bond B2
                 WHERE B1.friend_id = B2.own_id
               )
       SELECT count(*) INTO :count
               FROM Friend
               WHERE (own_id = :Xsid and friend_id = :Ysid) OR
                     (own_id = :Ysid and friend_id = :Xsid);

       if (count > 0) {
         printf ("X and Y are indirect friends!\n");
         return;
       }

}

When I compile it I get this error at compile time:

LINE    MESSAGES FOR main.sqc
------  ----------------------------------------------------------------
SQL0060W  The "C" precompiler is in progress.
1096   SQL0104N  An unexpected token ":count" was found
                 following "SELECT count(*) INTO".  Expected tokens may
                 include:  "<space>".  SQLSTATE=42601
       SQL0092N  No package was created because of previous
                 errors.
       SQL0091W  Precompilation or binding was ended with "2"
                 errors and "0" warnings.

Any clues what's going on!?!?

Thanx.



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

Предыдущее
От: "C. Miller"
Дата:
Сообщение: Import from MS SQL Server?
Следующее
От: ville80@salo.salonseutu.fi (9902468)
Дата:
Сообщение: Re: System catalog and identifying