pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedcreate function using language SQL
3+ messages / 3 participants
[nested] [flat]
* create function using language SQL
@ 2001-08-14 12:40 Gary Stainburn <gary.stainburn@ringways.co.uk>
0 siblings, 2 replies; 3+ messages in thread
From: Gary Stainburn @ 2001-08-14 12:40 UTC (permalink / raw)
To: pgsql-sql
Hi all,
As I was reading up on create function etc. while learning plpgsql, I seam to
remember it stated that as well as plpgsql, that other languages are/will be
available including using SQL as the language. However, I cannot find the
syntax to create a function in SQL. Specifically, how you return the result.
As an example, how would I create a SQL function to match the plpgsql
function below?
CREATE FUNCTION getteamno(int4) RETURNS varchar AS '
DECLARE
unitno varchar;
BEGIN
select into unitno
tregion || ''/'' ||
to_char(tnumber,''FM000'')
from teams
where tid = $1;
if not found then
raise exception ''Team % not found'',$1;
return '''';
end if;
return unitno;
END;
' LANGUAGE 'plpgsql';
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: create function using language SQL
@ 2001-08-14 13:40 Jeff Eckermann <jeckermann@verio.net>
parent: Gary Stainburn <gary.stainburn@ringways.co.uk>
1 sibling, 0 replies; 3+ messages in thread
From: Jeff Eckermann @ 2001-08-14 13:40 UTC (permalink / raw)
To: Gary Stainburn <gary.stainburn@ringways.co.uk>; +Cc: pgsql-sql
The "create function" syntax is the same. The language syntax is straight
SQL:
CREATE FUNCTION getteamno(int4) RETURNS varchar AS '
SELECT tregion || ''/'' || to_char(tnumber, ''FM000'')
FROM teams
WHERE tid = $1
' LANGUAGE 'sql';
You don't get to build in error checking, but there has to be a reason to
use plpgsql :-)
SQL is non-procedural, after all.
Check the docs: Reference Manual/SQL Commands/Create Function
----- Original Message -----
From: "Gary Stainburn" <gary.stainburn@ringways.co.uk>
To: <pgsql-sql@postgresql.org>
Sent: Tuesday, August 14, 2001 7:40 AM
Subject: create function using language SQL
> Hi all,
>
> As I was reading up on create function etc. while learning plpgsql, I seam
to
> remember it stated that as well as plpgsql, that other languages are/will
be
> available including using SQL as the language. However, I cannot find the
> syntax to create a function in SQL. Specifically, how you return the
result.
>
> As an example, how would I create a SQL function to match the plpgsql
> function below?
>
>
> CREATE FUNCTION getteamno(int4) RETURNS varchar AS '
> DECLARE
> unitno varchar;
> BEGIN
> select into unitno
> tregion || ''/'' ||
> to_char(tnumber,''FM000'')
> from teams
> where tid = $1;
> if not found then
> raise exception ''Team % not found'',$1;
> return '''';
> end if;
> return unitno;
> END;
> ' LANGUAGE 'plpgsql';
>
> --
> Gary Stainburn
>
> This email does not contain private or confidential material as it
> may be snooped on by interested government parties for unknown
> and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: create function using language SQL
@ 2001-08-14 14:40 Tom Lane <tgl@sss.pgh.pa.us>
parent: Gary Stainburn <gary.stainburn@ringways.co.uk>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2001-08-14 14:40 UTC (permalink / raw)
To: Gary Stainburn <gary.stainburn@ringways.co.uk>; +Cc: pgsql-sql
Gary Stainburn <gary.stainburn@ringways.co.uk> writes:
> ... However, I cannot find the
> syntax to create a function in SQL. Specifically, how you return the result.
See
http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/xfunc.html#XFUNC-SQL
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-08-14 14:40 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-08-14 12:40 create function using language SQL Gary Stainburn <gary.stainburn@ringways.co.uk>
2001-08-14 13:40 ` Jeff Eckermann <jeckermann@verio.net>
2001-08-14 14:40 ` Tom Lane <tgl@sss.pgh.pa.us>
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