X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 34CF9475AE5 for ; Sun, 27 Apr 2003 06:39:21 -0400 (EDT) Received: from mail.uni-magdeburg.de (mail.uni-magdeburg.de [141.44.1.10]) by postgresql.org (Postfix) with ESMTP id 8BF3D474E42 for ; Sun, 27 Apr 2003 06:39:20 -0400 (EDT) Received: from wh59-504.st.uni-magdeburg.de ([141.44.198.154] helo=bubke.de) by mail.uni-magdeburg.de with esmtp (EXIM Version 3.36) for id 199jYy-0005d6-00; Sun, 27 Apr 2003 12:39:16 +0200 Message-ID: <3EABB301.5040000@bubke.de> Date: Sun, 27 Apr 2003 12:37:53 +0200 From: Marco Bubke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Second maximum value Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Scanner: exiscan *199jYy-0005d6-00*ew9GrZHgD8c* (Otto-von-Guericke Universitaet Magdeburg, Germany) X-Spam-Status: No, hits=-12.9 required=5.0 tests=BAYES_01,USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/402 X-Sequence-Number: 13103 Hello I'm new to postgres and I have tried to write a function which returns the second(third...) maximum to use it in a aggregation. But it's not function and I have no clue whats wrong. Here what I do: create type counter_max as ( maximum real, value int ); create function get_counter_max(real, int) returns counter_max as 'select $1, $2' language sql; create or replace function x_max(counter_max, real) returns counter_max as ' declare maxi alias for $1; value alias for $2; result counter_max; begin if maxi.counter = 0 then return maxi; elsif value >= maxi.maximum then result.maximum := value; result.counter := maxi.counter -1; return result; else return maxi; end if; end; ' language 'plpgsql'; When I execute: select x_max(get_counter_max(1., 1), 2.::real); it says: WARNING: plpgsql: ERROR during compile of x_max near line 11 ERROR: return type mismatch in function returning tuple at or near "result" Thanks in advance Marco