pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: bilal ghayyad <bilmar_gh@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: PostgreSQL Function: how to know the number of the returned results of the Query
Date: Mon, 31 Aug 2009 17:53:23 -0700 (PDT)
Message-ID: <675038.56213.qm@web53902.mail.re2.yahoo.com> (raw)

Hi List;

I am building a function in the SQL (PostgreSQL), so I will be able to call 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)
  RETURNS integer AS
$BODY$
DECLARE
BEGIN
         rate numberic(9,4);
	SELECT rate from voiptariff where id= 9;
         IF num_rows ==1 THEN   -- As example, but I am asking how to do it?
         .............
         ELSE
         .............
         END IF
END
$BODY$
  LANGUAGE 'sql' IMMUTABLE
  COST 100;
ALTER FUNCTION get_bool(text) OWNER TO gkradius;

In this function, I need to check the number of returned rows of the statement: SELECT rate from voiptariff where id= 9; because based on it I am going to build if statment, How?

Any help?

Regards
Bilal


      



view thread (3+ messages)  latest in thread

Message-ID: <675038.56213.qm@web53902.mail.re2.yahoo.com>
Permalink:  ../675038.56213.qm@web53902.mail.re2.yahoo.com/
Also on:    postgresql.org/message-id/675038.56213.qm@web53902.mail.re2.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bilmar_gh@yahoo.com
  Subject: Re: PostgreSQL Function: how to know the number of the returned results of the Query
  In-Reply-To: <675038.56213.qm@web53902.mail.re2.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox