Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f9e497d

Browse files
committed
Doco updates for change to handling of INTERNAL function
entries (prosrc is now name of C-level function).
1 parent 77d3355 commit f9e497d

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
lines changed

src/man/catalogs.3

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/catalogs.3,v 1.5 1998/03/25 01:54:49 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/catalogs.3,v 1.6 1999/05/20 02:44:53 tgl Exp $
44
.TH "SYSTEM CATALOGS" INTRO 03/13/94 PostgreSQL PostgreSQL
55
.SH "Section 7 - System Catalogs"
66
.de LS
@@ -316,8 +316,12 @@ pg_proc
316316
size) */
317317
int4 prooutin_ratio /* size of the function's output as a
318318
percentage of the size of the input */
319-
text prosrc /* function definition (postquel only) */
320-
bytea probin /* path to object file (C only) */
319+
text prosrc /* function definition:
320+
INTERNAL function: actual C name of function
321+
C function: currently, this field is unused
322+
SQL function: text of query(s)
323+
PL function: text in procedural language */
324+
bytea probin /* path to object file (C functions only) */
321325
.fi
322326
.nf M
323327
pg_language

src/man/create_function.l

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/create_function.l,v 1.10 1998/06/24 13:21:24 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/create_function.l,v 1.11 1999/05/20 02:44:53 tgl Exp $
44
.TH "CREATE FUNCTION" SQL 11/05/95 PostgreSQL PostgreSQL
55
.SH "NAME"
66
create function - define a new function
@@ -9,8 +9,9 @@ create function - define a new function
99
\fBcreate function\fP function_name
1010
\fB(\fP[type1 {, type-n}]\fB)\fP
1111
\fBreturns\fP type-r
12-
\fBas\fP {'/full/path/to/objectfile' | 'sql-queries'}
13-
\fBlanguage\fP {'c' \ 'sql' \ 'internal' \ 'plname'}
12+
\fBas\fP { '/full/path/to/objectfile' | 'sql-queries' |
13+
'builtin-function-name' | 'pl-program-text' }
14+
\fBlanguage\fP { 'c' | 'sql' | 'internal' | 'plname' }
1415
.fi
1516
.SH "DESCRIPTION"
1617
With this command, a Postgres user can register a function with Postgres.
@@ -35,9 +36,8 @@ or
3536
.IR "plname"
3637
is the language name of a created procedural language. See
3738
create_language(l) for details.)
38-
(The
39-
.IR "arg is"
40-
clause may be left out if the function has no arguments, or
39+
(The argument list
40+
may be left out if the function has no arguments, or
4141
alternatively the argument list may be left empty.)
4242
The input types may be base or complex types, or
4343
.IR opaque .
@@ -54,32 +54,43 @@ modifier indicates that the function will return a set of items,
5454
rather than a single item.
5555
The
5656
.IR as
57-
clause of the command is treated differently for C and SQL
58-
functions, as explained below.
57+
clause of the command is treated differently depending on the language,
58+
as explained below.
59+
.SH "INTERNAL FUNCTIONS"
60+
Internal functions are functions written in C which have been statically
61+
linked into the postgres backend process. The
62+
.BR as
63+
clause gives the C-language name of the function, which need not be the
64+
same as the name being declared for SQL use. (For reasons of backwards
65+
compatibility, an empty
66+
.BR as
67+
string is accepted as meaning that the C-language function name is the
68+
same as the SQL name.) Normally, all internal functions present in the
69+
backend are declared as SQL functions during database initialization,
70+
but a user could use
71+
.BR "create function"
72+
to create additional alias names for an internal function.
5973
.SH "C FUNCTIONS"
6074
Functions written in C can be defined to Postgres, which will dynamically
61-
load them into its address space. The loading happens either using
75+
load them into its address space. The
76+
.IR as
77+
clause gives the full path name of the object file that contains the
78+
function. This file is loaded either using
6279
.IR load(l)
6380
or automatically the first time the function is necessary for
6481
execution. Repeated execution of a function will cause negligible
6582
additional overhead, as the function will remain in a main memory
6683
cache.
67-
.PP
68-
Internal functions are functions written in C which have been statically
69-
linked into the postgres backend process. The
70-
.BR as
71-
clause must still be specified when defining an internal function but
72-
the contents are ignored.
7384
.SH "Writing C Functions"
74-
The body of a C function following
85+
For a C function, the string following
7586
.BR as
7687
should be the
7788
.BR "FULL PATH"
78-
of the object code (.o file) for the function, bracketed by quotation
89+
of the object code file for the function, bracketed by quotation
7990
marks. (Postgres will not compile a function automatically - it must
8091
be compiled before it is used in a
81-
.BR "define function"
82-
command.)
92+
.BR "create function"
93+
command. See below for additional information.)
8394
.PP
8495
C functions with base type arguments can be written in a
8596
straightforward fashion. The C equivalents of built-in Postgres types
@@ -297,7 +308,7 @@ on. If an argument is complex, then a \*(lqdot\*(rq notation may be
297308
used to access attributes of the argument (e.g. \*(lq$1.emp\*(rq), or
298309
to invoke functions via a nested-dot syntax.
299310
.SH "PL FUNCTIONS"
300-
Procedural languages aren't builtin to Postgres. They are offered
311+
Procedural languages aren't built into Postgres. They are offered
301312
by loadable modules. Please refer to the documentation for the
302313
PL in question for details about the syntax and how the
303314
.IR "as"
@@ -400,10 +411,11 @@ A function may also have the same name as an attribute. In the case
400411
that there is an ambiguity between a function on a complex type and
401412
an attribute of the complex type, the attribute will always be used.
402413
.SH "RESTRICTIONS"
403-
The name of the C function must be a legal C function name, and the
404-
name of the function in C code must be exactly the same as the name
405-
used in
406-
.BR "create function" .
414+
For functions written in C, the SQL name declared in
415+
.BR "create function"
416+
must be exactly the same as the actual name of the function in the
417+
C code (hence it must be a legal C function name).
418+
.PP
407419
There is a subtle implication of this restriction: while the
408420
dynamic loading routines in most operating systems are more than
409421
happy to allow you to load any number of shared libraries that
@@ -422,6 +434,14 @@ define a set of C functions with different names and then define
422434
a set of identically-named SQL function wrappers that take the
423435
appropriate argument types and call the matching C function.
424436
.PP
437+
Another solution is not to use dynamic loading, but to link your
438+
functions into the backend statically and declare them as INTERNAL
439+
functions. Then, the functions must all have distinct C names but
440+
they can be declared with the same SQL names (as long as their
441+
argument types differ, of course). This way avoids the overhead of
442+
an SQL wrapper function, at the cost of more effort to prepare a
443+
custom backend executable.
444+
.PP
425445
.IR opaque
426446
cannot be given as an argument to a SQL function.
427447
.SH "BUGS"

0 commit comments

Comments
 (0)