pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedFunction to retrieve the Id column
2+ messages / 2 participants
[nested] [flat]
* Function to retrieve the Id column
@ 2006-08-24 17:07 Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2006-08-24 18:13 ` Re: Function to retrieve the Id column Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 2+ messages in thread
From: Ezequias Rodrigues da Rocha @ 2006-08-24 17:07 UTC (permalink / raw)
To: pgsql-sql
Hi list,
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)
Best regards ...
Ezequias
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Function to retrieve the Id column
2006-08-24 17:07 Function to retrieve the Id column Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
@ 2006-08-24 18:13 ` Michael Fuhr <mike@fuhr.org>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Fuhr @ 2006-08-24 18:13 UTC (permalink / raw)
To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql
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.html
http://www.postgresql.org/docs/8.1/interactive/xfunc-sql.html
http://www.postgresql.org/docs/8.1/interactive/plpgsql.html
--
Michael Fuhr
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-08-24 18:13 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-24 17:07 Function to retrieve the Id column Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2006-08-24 18:13 ` Michael Fuhr <mike@fuhr.org>
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