From: Michael Fuhr <mike@fuhr.org>
To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Function to retrieve the Id column
Date: Thu, 24 Aug 2006 12:13:49 -0600
Message-ID: <20060824181348.GA31220@winnie.fuhr.org> (raw)
In-Reply-To: <55c095e90608241007t3d004a14w9720cd66a60772e@mail.gmail.com>
References: <55c095e90608241007t3d004a14w9720cd66a60772e@mail.gmail.com>
On Thu, Aug 24, 2006 at 02:07:14PM -0300, Ezequias Rodrigues da Rocha wrote:
> I have Id field that is used in all my database but my more often used
> parameter is a column called "number" that I have in more than 5000 magnetic
> cards, my question is.
>
> How could I make a function to retrieve this Id just passing the number as
> parameter, just like:
>
> getCardId(number: varchar)
Are you looking for something like this?
CREATE FUNCTION getCardId(varchar) RETURNS integer AS $$
SELECT id FROM table_name WHERE number = $1;
$$ LANGUAGE sql STABLE STRICT;
Here's an example of how you'd call this function:
SELECT getCardId('123456');
See "Server Programming" in the documentation for more information
about how to write functions.
http://www.postgresql.org/docs/8.1/interactive/server-programming.htmlhttp://www.postgresql.org/docs/8.1/interactive/xfunc-sql.htmlhttp://www.postgresql.org/docs/8.1/interactive/plpgsql.html
--
Michael Fuhr
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: mike@fuhr.org, ezequias.rocha@gmail.com
Subject: Re: Function to retrieve the Id column
In-Reply-To: <20060824181348.GA31220@winnie.fuhr.org>
* 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