psani funkce v pgsql

Jiri Chaloupka dev na b2bexpander.com
Úterý Prosinec 3 11:44:12 CET 2002


Dobry den,
navazu na starsi thread a budu se jeste chvili ptat ...

mam procedurku (zatim jeste neni cela ale pro tento ucel dostacujici):

CREATE FUNCTION procdd(integer) RETURNS boolean AS '
    DECLARE
       --  ....
       -- Nasledne je treba v ramci jobu provest select na temporary tabulku
       -- PRIKLAD UZITI
       -- select procdd();
       -- select * from tempdd;

       -- obsahuje id dealera
       iddealer alias for $1;

    BEGIN
       create temporary table tempdd as select d.id, d.usr,
           (select count(*) from sells where dealerid = d.id and imei !=
'') as sells,
           (select count(*) from sells where dealerid = d.id and imei !=
'' and stateid = 1) as oksells,
           (select count(*) from sells where dealerid = d.id and imei !=
'' and stateid not in (1,4)) as failsells,
           (select sum(points) from sells where dealerid = d.id and imei
!= '' and stateid = 1) as allpoints,
           (select sum(points) from sells where dealerid = d.id and fanr >
0) as fapoints
       from dealer d
       where d.id = iddealer;

        -- Return the boolean
       return true;

    END;
' language 'plpgsql';

kdyz zavolam ciste onen select, ktery je obsahem, dostanu:

  id  | usr  | sells | oksells | failsells | allpoints | fapoints
------+------+-------+---------+-----------+-----------+----------
 2834 | 1921 |  1492 |    1330 |       162 |     11504 |

ale kdyz pouziju proceduru, nejsou tam vsechny sloupce, navic nesedi
vysledek:

db=# select procdd(2834);
 procdd
--------
 t
(1 row)

db=# select * from tempdd;
  id  | usr  | oksells | allpoints | fapoints
------+------+---------+-----------+----------
 2834 | 1921 |    1330 |      1330 |
(1 row)

proc? Kde je ona zasadni chyba v procedure?




Další informace o konferenci Test