Обсуждение: writing a function without installing a language
is there a way to write a function without installing a specific language? all i need to do is write a function that can take 3 text's and put them into a list format (eg. "text1, text2 and text3" ) can anyone help?
On Friday 16 May 2008 7:56 am, ${spencer} wrote:
> is there a way to write a function without installing a specific
> language? all i need to do is write a function that can take 3 text's
> and put them into a list format (eg. "text1, text2 and text3" )
>
> can anyone help?
You can use C or SQL to write a function as they are "preinstalled".
See:
http://www.postgresql.org/docs/8.3/interactive/xfunc.html
--
Adrian Klaver
aklaver@comcast.net
${spencer} wrote:
> is there a way to write a function without installing a specific
> language? all i need to do is write a function that can take 3 text's
> and put them into a list format (eg. "text1, text2 and text3" )
Does PL/PgSQL count as a "language" for your purposes?
PL/PgSQL is built and shipped with the postgreSQL server. It's
essentially always installed. By default it's just not enabled for
access in any database.
The statement:
CREATE LANGUAGE plpgsql;
just tells a given database that PL/PgSQL should be available.
Failing that, you might be able to use an SQL function (though I don't
really see how you'd handle the special case for "and" without a
subquery to obtain a total result count) or write a C extension to do it.
Using PL/PgSQL is certainly the easy way.
--
Craig Ringer
On Friday 16. May 2008, ${spencer} wrote:
>is there a way to write a function without installing a specific
>language? all i need to do is write a function that can take 3 text's
>and put them into a list format (eg. "text1, text2 and text3" )
>
>can anyone help?
sandbox=> create function foo(text,text,text) returns text as $$
sandbox$> select $1 || ', ' || $2 || ', and ' || $3
sandbox$> $$ language sql stable;
CREATE FUNCTION
sandbox=> select foo('x','y','z');
foo
-------------
x, y, and z
(1 row)
sandbox=>
--
Leif Biberg Kristensen | Registered Linux User #338009
http://solumslekt.org/ | Cruising with Gentoo/KDE
My Jazz Jukebox: http://www.last.fm/user/leifbk/
Craig Ringer wrote:
> ${spencer} wrote:
>> is there a way to write a function without installing a specific
>> language? all i need to do is write a function that can take 3 text's
>> and put them into a list format (eg. "text1, text2 and text3" )
> Failing that, you might be able to use an SQL function (though I don't
> really see how you'd handle the special case for "and" without a
> subquery to obtain a total result count)
... if the input was a set of `text', not 3 individual `text' arguments.
Whoops. It's trivially done with plain SQL.
--
Craig Ringer
thanks for the help guys, i've solved the problem using PL/PgSQL. once i had "created" the language it was really rather simple. thanks again