Re: PLPGSQL problem with SELECT INTO
От | Jay O'Connor |
---|---|
Тема | Re: PLPGSQL problem with SELECT INTO |
Дата | |
Msg-id | 20030529151652.C1144@altaica обсуждение исходный текст |
Ответ на | PLPGSQL problem with SELECT INTO ("Jay O'Connor" <joconnor@cybermesa.com>) |
Список | pgsql-general |
> OK, I'm trying to count the number of records based on two criteria, this > works at the psql prompt but not in a plpgsql function > > SELECT count(*) FROM mytable WHERE fieldone = 'val1' AND fieldtwo > = > 'val2'; > > This gives me back '4' which is what I expect (trust me :) > > but if I try to put this in a PLPGSQL function, it doesn't work. > > CREATE FUNCTION countRows (varchar, varchar) RETURNS int AS > ' > DECLARE > val1 ALIAS FOR $1; > val2 ALIAS FOR $2; > total int; > BEGIN > SELECT INTO total count(*) FROM mytable WHERE fieldone = > val1 AND fieldtwo = val2; > RETURN total; > END; > ' LANGUAGE PLPGSQL; After some furtehr research I determined that it was ignoring the fieldTwo check completely. I finally narrowerd it ddown because my code read fieldTwo ALIAS FOR $2; and the query read SELECT .....fieldtwo = fieldTwo And plpgsql was not being case sensitive and thought it was comparing it to itself. Take care, Jay
В списке pgsql-general по дате отправления: