Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc99e851

Browse files
committed
Clean up sql functions examples.
1 parenta987653 commitc99e851

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

‎doc/src/sgml/xfunc.sgml

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.15 2000/05/18 14:24:32 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.16 2000/05/20 11:24:37 momjian Exp $
33
-->
44

55
<chapter id="xfunc">
@@ -87,11 +87,13 @@ $Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.15 2000/05/18 14:24:32 momji
8787
which might be used to debit a bank account:
8888

8989
<programlisting>
90-
create function TP1 (int4, float8) returns int4
91-
as 'update BANK set balance = BANK.balance - $2
92-
where BANK.acctountno = $1
93-
select(x = 1)'
94-
language 'sql';
90+
CREATE FUNCTION tp1 (int4, float8)
91+
RETURNS int4
92+
AS 'UPDATE bank
93+
SET balance = bank.balance - $2
94+
WHERE bank.acctountno = $1;
95+
SELECT 1;'
96+
LANGUAGE 'sql';
9597
</programlisting>
9698

9799
A user could execute this function to debit account 17 by $100.00 as
@@ -108,7 +110,7 @@ select (x = TP1( 17,100.0));
108110

109111
<programlisting>
110112
select function hobbies (EMP) returns set of HOBBIES
111-
as 'select(HOBBIES.all) from HOBBIES
113+
as 'select HOBBIES.* from HOBBIES
112114
where $1.name = HOBBIES.person'
113115
language 'sql';
114116
</programlisting>
@@ -123,8 +125,10 @@ select function hobbies (EMP) returns set of HOBBIES
123125
simply returns a base type, such as <literal>int4</literal>:
124126

125127
<programlisting>
126-
CREATE FUNCTION one() RETURNS int4
127-
AS 'SELECT 1 as RESULT' LANGUAGE 'sql';
128+
CREATE FUNCTION one()
129+
RETURNS int4
130+
AS 'SELECT 1 as RESULT;'
131+
LANGUAGE 'sql';
128132

129133
SELECT one() AS answer;
130134

@@ -149,8 +153,10 @@ SELECT one() AS answer;
149153
and $2:
150154

151155
<programlisting>
152-
CREATE FUNCTION add_em(int4, int4) RETURNS int4
153-
AS 'SELECT $1 + $2;' LANGUAGE 'sql';
156+
CREATE FUNCTION add_em(int4, int4)
157+
RETURNS int4
158+
AS 'SELECT $1 + $2;'
159+
LANGUAGE 'sql';
154160

155161
SELECT add_em(1, 2) AS answer;
156162

@@ -175,12 +181,14 @@ SELECT add_em(1, 2) AS answer;
175181
salary would be if it were doubled:
176182

177183
<programlisting>
178-
CREATE FUNCTION double_salary(EMP) RETURNS int4
179-
AS 'SELECT $1.salary * 2 AS salary;' LANGUAGE 'sql';
184+
CREATE FUNCTION double_salary(EMP)
185+
RETURNS int4
186+
AS 'SELECT $1.salary * 2 AS salary;'
187+
LANGUAGE 'sql';
180188

181189
SELECT name, double_salary(EMP) AS dream
182-
FROM EMP
183-
WHERE EMP.cubicle ~= '(2,1)'::point;
190+
FROM EMP
191+
WHERE EMP.cubicle ~= '(2,1)'::point;
184192

185193

186194
+-----+-------+
@@ -223,12 +231,13 @@ SELECT name(EMP) AS youngster
223231
that returns a single EMP instance:
224232

225233
<programlisting>
226-
CREATE FUNCTION new_emp() RETURNS EMP
227-
AS 'SELECT \'None\'::text AS name,
228-
1000 AS salary,
229-
25 AS age,
230-
\'(2,2)\'::point AS cubicle'
231-
LANGUAGE 'sql';
234+
CREATE FUNCTION new_emp()
235+
RETURNS EMP
236+
AS 'SELECT \'None\'::text AS name,
237+
1000 AS salary,
238+
25 AS age,
239+
\'(2,2)\'::point AS cubicle'
240+
LANGUAGE 'sql';
232241
</programlisting>
233242
</para>
234243
<para>
@@ -303,10 +312,12 @@ NOTICE:parser: syntax error at or near "."
303312
specified as the function's returntype.
304313

305314
<programlisting>
306-
CREATE FUNCTION clean_EMP () RETURNS int4
307-
AS 'DELETE FROM EMP WHERE EMP.salary &lt;= 0;
308-
SELECT 1 AS ignore_this'
309-
LANGUAGE 'sql';
315+
CREATE FUNCTION clean_EMP ()
316+
RETURNS int4
317+
AS 'DELETE FROM EMP
318+
WHERE EMP.salary &lt;= 0;
319+
SELECT 1 AS ignore_this;'
320+
LANGUAGE 'sql';
310321

311322
SELECT clean_EMP();
312323

@@ -837,8 +848,10 @@ str = (char *) GetAttributeByName(t, "name", &amp;isnull)
837848
know about the c_overpaid function:
838849

839850
<programlisting>
840-
* CREATE FUNCTION c_overpaid(EMP, int4) RETURNS bool
841-
AS '<replaceable>PGROOT</replaceable>/tutorial/obj/funcs.so' LANGUAGE 'c';
851+
CREATE FUNCTION c_overpaid(EMP, int4)
852+
RETURNS bool
853+
AS '<replaceable>PGROOT</replaceable>/tutorial/obj/funcs.so'
854+
LANGUAGE 'c';
842855
</programlisting>
843856
</para>
844857

@@ -999,7 +1012,7 @@ str = (char *) GetAttributeByName(t, "name", &amp;isnull)
9991012

10001013
<para>
10011014
For functions written in C, the SQL name declared in
1002-
<command>CREATEFUNCTION</command>
1015+
<command>CREATEFUNC TION</command>
10031016
must be exactly the same as the actual name of the function in the
10041017
C code (hence it must be a legal C function name).
10051018
</para>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp