Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 637F0632722 for ; Tue, 1 Sep 2009 02:36:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 86059-10 for ; Tue, 1 Sep 2009 05:35:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-yx0-f193.google.com (mail-yx0-f193.google.com [209.85.210.193]) by mail.postgresql.org (Postfix) with ESMTP id 0856E634B6C for ; Tue, 1 Sep 2009 02:35:54 -0300 (ADT) Received: by yxe31 with SMTP id 31so1194435yxe.29 for ; Mon, 31 Aug 2009 22:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=i7MGlpE7HqmXGGZ1iccoPx0+njzlkTG2PwX3ZZh0TMQ=; b=C5tVmCMRim+uTLlPY8CFQVnvmnB3EuppPT0YwUFw3ToBptr8iTLxf2K1b5wdGJMNaa i5/bIquJcaoswWzCpM53f9i59zo1JsoWbOxlm9ccO4+wjtxJWRxLn9wCCp/WoDSYIknr RnB7jGURKDTahAvnwtlJlKUQKBk38NStNy6Dw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=e1W4QlmlSUZCog9uaeYrBrKCBCke6zpvQVjdCpaFeTM8+V1I+VyNYKChS+Su7Dki/F iJ5DAmW0KXUuF/38p42hhZPjPfHgBd0lZIkB565rKAiN4ScHzX3niw5/p/4Arxd6/N6z hhAYjdAduPv4XspX8ECpzXONeoeD22sTfbEoU= MIME-Version: 1.0 Received: by 10.151.29.10 with SMTP id g10mr10883274ybj.9.1251783353987; Mon, 31 Aug 2009 22:35:53 -0700 (PDT) In-Reply-To: <675038.56213.qm@web53902.mail.re2.yahoo.com> References: <675038.56213.qm@web53902.mail.re2.yahoo.com> Date: Tue, 1 Sep 2009 07:35:53 +0200 Message-ID: <162867790908312235t232a86d8sbeded1c02b62ae92@mail.gmail.com> Subject: Re: PostgreSQL Function: how to know the number of the returned results of the Query From: Pavel Stehule To: bilal ghayyad Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200909/1 X-Sequence-Number: 33066 Hello look on PERFORM and GET DIAGNOSTICS statements http://www.postgresql.org/docs/8.2/static/plpgsql-statements.html#PLPGSQL-S= TATEMENTS-SQL-NORESULT http://www.postgresql.org/docs/8.2/static/plpgsql-statements.html#PLPGSQL-S= TATEMENTS-DIAGNOSTICS regards Pavel Stehule 2009/9/1 bilal ghayyad : > Hi List; > > I am building a function in the SQL (PostgreSQL), so I will be able to ca= ll this function using a SELECT query. Inside the body of this function, I = was need to do the following but not able to know how: > > I have a SELECT statement (inside the function script itself), and I need= to know the number of the returned rows of that select query, if it is one= row or 2 or 3 , ... How? In which paramter I will be able to check this? > > For example, I have the following function: > > CREATE OR REPLACE FUNCTION get_credit_time(text, text) > =C2=A0RETURNS integer AS > $BODY$ > DECLARE > BEGIN > =C2=A0 =C2=A0 =C2=A0 =C2=A0 rate numberic(9,4); > =C2=A0 =C2=A0 =C2=A0 =C2=A0SELECT rate from voiptariff where id=3D 9; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 IF num_rows =3D=3D1 THEN =C2=A0 -- As example= , but I am asking how to do it? > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ............. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ELSE > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ............. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 END IF > END > $BODY$ > =C2=A0LANGUAGE 'sql' IMMUTABLE > =C2=A0COST 100; > ALTER FUNCTION get_bool(text) OWNER TO gkradius; > > In this function, I need to check the number of returned rows of the stat= ement: SELECT rate from voiptariff where id=3D 9; because based on it I am = going to build if statment, How? > > Any help? > > Regards > Bilal > > > > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql >