Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
c99e851e
Commit
c99e851e
authored
May 20, 2000
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up sql functions examples.
parent
a9876533
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
28 deletions
+41
-28
doc/src/sgml/xfunc.sgml
doc/src/sgml/xfunc.sgml
+41
-28
No files found.
doc/src/sgml/xfunc.sgml
View file @
c99e851e
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.1
5 2000/05/18 14:24:32
momjian Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.1
6 2000/05/20 11:24:37
momjian Exp $
-->
<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
which might be used to debit a bank account:
<programlisting>
create function TP1 (int4, float8) returns int4
as 'update BANK set balance = BANK.balance - $2
where BANK.acctountno = $1
select(x = 1)'
language 'sql';
CREATE FUNCTION tp1 (int4, float8)
RETURNS int4
AS ' UPDATE bank
SET balance = bank.balance - $2
WHERE bank.acctountno = $1;
SELECT 1;'
LANGUAGE 'sql';
</programlisting>
A user could execute this function to debit account 17 by $100.00 as
...
...
@@ -108,7 +110,7 @@ select (x = TP1( 17,100.0));
<programlisting>
select function hobbies (EMP) returns set of HOBBIES
as 'select
(HOBBIES.all)
from HOBBIES
as 'select
HOBBIES.*
from HOBBIES
where $1.name = HOBBIES.person'
language 'sql';
</programlisting>
...
...
@@ -123,8 +125,10 @@ select function hobbies (EMP) returns set of HOBBIES
simply returns a base type, such as <literal>int4</literal>:
<programlisting>
CREATE FUNCTION one() RETURNS int4
AS 'SELECT 1 as RESULT' LANGUAGE 'sql';
CREATE FUNCTION one()
RETURNS int4
AS 'SELECT 1 as RESULT;'
LANGUAGE 'sql';
SELECT one() AS answer;
...
...
@@ -149,8 +153,10 @@ SELECT one() AS answer;
and $2:
<programlisting>
CREATE FUNCTION add_em(int4, int4) RETURNS int4
AS 'SELECT $1 + $2;' LANGUAGE 'sql';
CREATE FUNCTION add_em(int4, int4)
RETURNS int4
AS 'SELECT $1 + $2;'
LANGUAGE 'sql';
SELECT add_em(1, 2) AS answer;
...
...
@@ -175,12 +181,14 @@ SELECT add_em(1, 2) AS answer;
salary would be if it were doubled:
<programlisting>
CREATE FUNCTION double_salary(EMP) RETURNS int4
AS 'SELECT $1.salary * 2 AS salary;' LANGUAGE 'sql';
CREATE FUNCTION double_salary(EMP)
RETURNS int4
AS 'SELECT $1.salary * 2 AS salary;'
LANGUAGE 'sql';
SELECT name, double_salary(EMP) AS dream
FROM EMP
WHERE EMP.cubicle ~= '(2,1)'::point;
FROM EMP
WHERE EMP.cubicle ~= '(2,1)'::point;
+-----+-------+
...
...
@@ -223,12 +231,13 @@ SELECT name(EMP) AS youngster
that returns a single EMP instance:
<programlisting>
CREATE FUNCTION new_emp() RETURNS EMP
AS 'SELECT \'None\'::text AS name,
CREATE FUNCTION new_emp()
RETURNS EMP
AS ' SELECT \'None\'::text AS name,
1000 AS salary,
25 AS age,
\'(2,2)\'::point AS cubicle'
LANGUAGE 'sql';
LANGUAGE 'sql';
</programlisting>
</para>
<para>
...
...
@@ -303,10 +312,12 @@ NOTICE:parser: syntax error at or near "."
specified as the function's returntype.
<programlisting>
CREATE FUNCTION clean_EMP () RETURNS int4
AS 'DELETE FROM EMP WHERE EMP.salary <= 0;
SELECT 1 AS ignore_this'
LANGUAGE 'sql';
CREATE FUNCTION clean_EMP ()
RETURNS int4
AS ' DELETE FROM EMP
WHERE EMP.salary <= 0;
SELECT 1 AS ignore_this;'
LANGUAGE 'sql';
SELECT clean_EMP();
...
...
@@ -837,8 +848,10 @@ str = (char *) GetAttributeByName(t, "name", &isnull)
know about the c_overpaid function:
<programlisting>
* CREATE FUNCTION c_overpaid(EMP, int4) RETURNS bool
AS '<replaceable>PGROOT</replaceable>/tutorial/obj/funcs.so' LANGUAGE 'c';
CREATE FUNCTION c_overpaid(EMP, int4)
RETURNS bool
AS '<replaceable>PGROOT</replaceable>/tutorial/obj/funcs.so'
LANGUAGE 'c';
</programlisting>
</para>
...
...
@@ -999,7 +1012,7 @@ str = (char *) GetAttributeByName(t, "name", &isnull)
<para>
For functions written in C, the SQL name declared in
<command>CREATE FUNCTION</command>
<command>CREATE FUNC
TION</command>
must be exactly the same as the actual name of the function in the
C code (hence it must be a legal C function name).
</para>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment