Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
5341cddb
Commit
5341cddb
authored
24 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Further polishing of documentation about new fmgr call convention.
parent
39b9c9f2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/src/sgml/xfunc.sgml
+39
-26
39 additions, 26 deletions
doc/src/sgml/xfunc.sgml
with
39 additions
and
26 deletions
doc/src/sgml/xfunc.sgml
+
39
−
26
View file @
5341cddb
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.3
0
2001/0
1/22 16:11:17
tgl Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.3
1
2001/0
2/15 19:03:35
tgl Exp $
-->
<chapter id="xfunc">
...
...
@@ -434,10 +434,9 @@ SELECT clean_EMP();
functions that will be loaded into Postgres. The "Defined In"
column gives the actual header file (in the
<filename>.../src/backend/</filename>
directory) that the equivalent C type is defined. However, if you
include <filename>utils/builtins.h</filename>,
these files will automatically be
included.
directory) that the equivalent C type is defined. Note that you should
always include <filename>postgres.h</filename> first, and that in turn
includes <filename>c.h</filename>.
<table tocentry="1">
<title>Equivalent C Types
...
...
@@ -619,9 +618,8 @@ SELECT clean_EMP();
<para>
By-value types can only be 1, 2 or 4 bytes in length
(even if your computer supports by-value types of other
sizes). <productname>Postgres</productname> itself
only passes integer types by value. You should be careful
(also 8 bytes, if sizeof(Datum) is 8 on your machine).
You should be careful
to define your types such that they will be the same
size (in bytes) on all architectures. For example, the
<literal>long</literal> type is dangerous because it
...
...
@@ -657,7 +655,9 @@ typedef struct
them in and out of <productname>Postgres</productname> functions.
To return a value of such a type, allocate the right amount of
memory with <literal>palloc()</literal>, fill in the allocated memory,
and return a pointer to it.
and return a pointer to it. (Alternatively, you can return an input
value of the same type by returning its pointer. <emphasis>Never</>
modify the contents of a pass-by-reference input value, however.)
</para>
<para>
...
...
@@ -721,8 +721,8 @@ memmove(destination->data, buffer, 40);
Here are some examples:
<programlisting>
#include <string.h>
#include "postgres.h"
#include <string.h>
/* By Value */
...
...
@@ -780,10 +780,10 @@ concat_text(text *arg1, text *arg2)
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
memset((void *) new_text, 0, new_text_size);
VARATT_SIZEP(new_text) = new_text_size;
strncpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
strncat(VARDATA(new_text), VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
memcpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
memcpy(VARDATA(new_text) + (VARSIZE(arg1)-VARHDRSZ),
VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
return new_text;
}
</programlisting>
...
...
@@ -882,8 +882,8 @@ PG_FUNCTION_INFO_V1(funcname);
Here we show the same functions as above, coded in version-1 style:
<programlisting>
#include <string.h>
#include "postgres.h"
#include <string.h>
#include "fmgr.h"
/* By Value */
...
...
@@ -945,7 +945,7 @@ copytext(PG_FUNCTION_ARGS)
*/
memcpy((void *) VARDATA(new_t), /* destination */
(void *) VARDATA(t), /* source */
VARSIZE(t)-VARHDRSZ);
/* how many bytes */
VARSIZE(t)-VARHDRSZ); /* how many bytes */
PG_RETURN_TEXT_P(new_t);
}
...
...
@@ -959,10 +959,10 @@ concat_text(PG_FUNCTION_ARGS)
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
memset((void *) new_text, 0, new_text_size);
VARATT_SIZEP(new_text) = new_text_size;
strncpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
strncat(VARDATA(new_text), VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
memcpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
memcpy(VARDATA(new_text) + (VARSIZE(arg1)-VARHDRSZ),
VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
PG_RETURN_TEXT_P(new_text);
}
</programlisting>
...
...
@@ -991,10 +991,20 @@ concat_text(PG_FUNCTION_ARGS)
</para>
<para>
The version-1 function call conventions also make it possible to
test for NULL inputs to a non-strict function, return a NULL
result (from either strict or non-strict functions), return
<quote>set</quote> results, and implement trigger functions and
One big improvement in version-1 functions is better handling of NULL
inputs and results. The macro <function>PG_ARGISNULL(n)</function>
allows a function to test whether each input is NULL (of course, doing
this is only necessary in functions not declared <quote>strict</>).
As with the
<function>PG_GETARG_<replaceable>xxx</replaceable>()</function> macros,
the input arguments are counted beginning at zero.
To return a NULL result, execute <function>PG_RETURN_NULL()</function>;
this works in both strict and non-strict functions.
</para>
<para>
The version-1 function call conventions make it possible to
return <quote>set</quote> results and implement trigger functions and
procedural-language call handlers. Version-1 code is also more
portable than version-0, because it does not break ANSI C restrictions
on function call protocol. For more details see
...
...
@@ -1167,11 +1177,14 @@ LANGUAGE 'c';
<listitem>
<para>
Most of the internal <productname>Postgres</productname> types
are declared in <filename>postgres.h</filename>, the function
are declared in <filename>postgres.h</filename>,
while
the function
manager interfaces (<symbol>PG_FUNCTION_ARGS</symbol>, etc.)
are in <filename>fmgr.h</filename>, so you will need to
include at least these two files. Including
<filename>postgres.h</filename> will also include
include at least these two files. For portability reasons it's best
to include <filename>postgres.h</filename> <emphasis>first</>,
before any other system or user header files.
Including <filename>postgres.h</filename> will also include
<filename>c.h</filename>,
<filename>elog.h</filename> and <filename>palloc.h</filename>
for you.
</para>
...
...
@@ -1210,7 +1223,7 @@ LANGUAGE 'c';
<title>Function Overloading</title>
<para>
More than one function may be defined with the same name,
a
s long as
More than one function may be defined with the same name, s
o
long as
the arguments they take are different. In other words, function names
can be <firstterm>overloaded</firstterm>.
A function may also have the same name as an attribute. In the case
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment