hi, i write a function in postgresql source code, how to register this function?

Started by sunpengalmost 16 years ago5 messagesgeneral
Jump to latest
#1sunpeng
bluevaley@gmail.com

hi,i write a function in postgresql source code, how to register this
function?
it is not an aggregate function.
i don't use 34.3"User-Defined Functions" described in
http://www.postgresql.org/docs/8.4/interactive/xfunc.html, i just write it
in postgresql sourcecode, how to register this function to let final user
use? Should i only add one tuple in pg_process table? how to add ?
thanks!
peng

In reply to: sunpeng (#1)
Re: hi,i write a function in postgresql source code, how to register this function?

On 16/06/2010 17:42, sunpeng wrote:

hi,i write a function in postgresql source code, how to register this
function?
it is not an aggregate function.
i don't use 34.3"User-Defined Functions" described in
http://www.postgresql.org/docs/8.4/interactive/xfunc.html, i just write
it in postgresql sourcecode, how to register this function to let final
user use? Should i only add one tuple in pg_process table? how to add ?

What do you mean by "PostgreSQL source code"? - SQL? pl/pgsql?

Generally, you just execute the following SQL command:

create or replace function my_function(.....) returns [return type]
as
$$
[function code here]
$$
language [whatever - usually sql or plpgsql] ;

....or am I missing something in your question?

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

#3sunpeng
bluevaley@gmail.com
In reply to: Raymond O'Donnell (#2)
Re: hi,i write a function in postgresql source code, how to register this function?

It's just in postgresql 8.4 source code,e.g in
/backend/executor/functions.c, not in sql,not in pl/pgsql

2010/6/16 Raymond O'Donnell <rod@iol.ie>

Show quoted text

On 16/06/2010 17:42, sunpeng wrote:

hi,i write a function in postgresql source code, how to register this
function?
it is not an aggregate function.
i don't use 34.3"User-Defined Functions" described in
http://www.postgresql.org/docs/8.4/interactive/xfunc.html, i just write
it in postgresql sourcecode, how to register this function to let final
user use? Should i only add one tuple in pg_process table? how to add ?

What do you mean by "PostgreSQL source code"? - SQL? pl/pgsql?

Generally, you just execute the following SQL command:

create or replace function my_function(.....) returns [return type]
as
$$
[function code here]
$$
language [whatever - usually sql or plpgsql] ;

....or am I missing something in your question?

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

#4Adrian von Bidder
avbidder@fortytwo.ch
In reply to: sunpeng (#1)
Re: hi, i write a function in postgresql source code, how to register this function?

Hi,

On Wednesday 16 June 2010 18.42:25 sunpeng wrote:

hi,i write a function in postgresql source code, how to register this
function?
it is not an aggregate function.
i don't use 34.3"User-Defined Functions" described in
http://www.postgresql.org/docs/8.4/interactive/xfunc.html, i just write
it in postgresql sourcecode, how to register this function to let final
user use? Should i only add one tuple in pg_process table? how to add ?

Perhaps, before thinking about the low-level implementation (where you wrote
the function): could you describe what you are trying to do and why you
think that you can not (or should not) do this with the usual pg extension
mechanisms as described in chapter 34 of the documentation?

In my experience, PostgreSQL can be made to do almost everything and needs
changes to the core code only in very rare cases.

If you've already written the code in C, perhaps you can adapt it to work as
a DSO as described in chapter 34.9 [1]<http://www.postgresql.org/docs/8.4/interactive/xfunc-c.html&gt;? I've never done this, but from my
understanding a C language module has nearly full access to all server
internals, so what you are doing in functions.c should also be possible from
an external module.

cheers
-- vbi

[1]: <http://www.postgresql.org/docs/8.4/interactive/xfunc-c.html&gt;

--
featured product: vim - http://vim.org

#5Dimitri Fontaine
dimitri@2ndQuadrant.fr
In reply to: sunpeng (#1)
Re: hi, i write a function in postgresql source code, how to register this function?

sunpeng <bluevaley@gmail.com> writes:

hi,i write a function in postgresql source code, how to register this function?

See src/include/catalog/pg_proc.h

But you should *really* consider making it a loadable module. That's the
way it makes sense for any code you want to add in the server unless
you're preparing a patch for PostgreSQL itself, or you're doing a new
Index Access Method that you want crash safe.

Regards,
--
dim