Custom Functions

Started by Matthew Metnetskyover 21 years ago5 messagesgeneral
Jump to latest
#1Matthew Metnetsky
met@uberstats.com

I'm trying to write two custom recursive functions: one that selects,
and the other that selects/updates.

I've been looking around the internet for examples for they're so
limiting and completely off track from what I need to do. The best
examples I can find is in the source code for Postgres, but that's so
complicated I barely have an idea whats going on with its limited
comments.

So, does anyone know of (or have) good examples of queries within
functions (and returning sets of data)?

Thanks in advance,

~ Matthew

#2Katsaros Kwn/nos
ntinos@aueb.gr
In reply to: Matthew Metnetsky (#1)
Re: Custom Functions

So, does anyone know of (or have) good examples of queries within
functions (and returning sets of data)?

I'm not very experienced in PostgreSQL but maybe SPI functions is what you
need.

Regards,
Ntinos Katsaros

#3Matthew Metnetsky
met@uberstats.com
In reply to: Katsaros Kwn/nos (#2)
Re: Custom Functions

On Tue, 2004-09-28 at 10:55, Katsaros Kwn/nos wrote:

So, does anyone know of (or have) good examples of queries within
functions (and returning sets of data)?

I'm not very experienced in PostgreSQL but maybe SPI functions is what you
need.

Yeah I took a look at them, but I'm not sold because when I look at
Postgres' build in functions I never see it. Its as if SPI_* is slower
or something.

Thanks though,

~ Matthew

#4Doug McNaught
doug@mcnaught.org
In reply to: Matthew Metnetsky (#3)
Re: Custom Functions

Matthew Metnetsky <met@uberstats.com> writes:

On Tue, 2004-09-28 at 10:55, Katsaros Kwn/nos wrote:

So, does anyone know of (or have) good examples of queries within
functions (and returning sets of data)?

I'm not very experienced in PostgreSQL but maybe SPI functions is what you
need.

Yeah I took a look at them, but I'm not sold because when I look at
Postgres' build in functions I never see it. Its as if SPI_* is slower
or something.

SPI is an internal API for server-side functions to use. Client apps
will never use it.

I think Katsaros might have meant "set-returning functions" (SRF)
which are documented in the manual and available to client apps.

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
--T. J. Jackson, 1863

#5Matthew Metnetsky
met@uberstats.com
In reply to: Matthew Metnetsky (#1)
Re: Custom Functions

Hello,

On Tue, 2004-09-28 at 13:57, Tim Penhey wrote:

Matthew Metnetsky wrote:

So, does anyone know of (or have) good examples of queries within
functions (and returning sets of data)?

Thanks in advance,

~ Matthew

Hi Matthew,

I wrote up an example which can be found at
http://www.scorefirst.com/postgresql.html, not sure if it is what you
are after or not.

Tim

That was the exact foundation I was looking for. I'm not sure why I
over looked plpgsql but I did, and its much easier than C custom
functions which are hideous and completely far from portable.

Thanks,

~ Matthew