2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2004-07-04 09:10:50 +00:00
|
|
|
<!-- $Revision: 1.21 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<reference id="ref.pgsql">
|
2004-02-24 08:46:39 +00:00
|
|
|
<title>PostgreSQL Functions</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<titleabbrev>PostgreSQL</titleabbrev>
|
|
|
|
|
|
|
|
<partintro>
|
2002-08-07 10:01:28 +00:00
|
|
|
<section id="pgsql.intro">
|
|
|
|
&reftitle.intro;
|
2002-04-15 00:12:54 +00:00
|
|
|
<para>
|
2002-08-07 10:01:28 +00:00
|
|
|
PostgreSQL database is Open Source product and available without
|
2003-02-22 23:21:57 +00:00
|
|
|
cost. Postgres, developed originally in the UC Berkeley Computer
|
2003-02-23 00:53:29 +00:00
|
|
|
Science Department, pioneered many of the object-relational concepts
|
|
|
|
now becoming available in some commercial databases. It provides
|
|
|
|
SQL92/SQL99 language support, transactions, referential integrity,
|
|
|
|
stored procedures and type extensibility. PostgreSQL is an open source
|
|
|
|
descendant of this original Berkeley code.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
2002-08-07 10:01:28 +00:00
|
|
|
</section>
|
|
|
|
|
2002-08-09 10:26:12 +00:00
|
|
|
<section id="pgsql.requirements">
|
2002-08-07 10:01:28 +00:00
|
|
|
&reftitle.required;
|
2002-04-15 00:12:54 +00:00
|
|
|
<para>
|
2002-08-07 10:01:28 +00:00
|
|
|
To use PostgreSQL support, you need PostgreSQL 6.5 or
|
|
|
|
later, PostgreSQL 7.0 or later to enable all PostgreSQL module
|
|
|
|
features. PostgreSQL supports many character encoding including
|
|
|
|
multibyte character encoding. The current version and more
|
2003-02-22 23:21:57 +00:00
|
|
|
information about PostgreSQL is available at
|
2003-02-23 00:53:29 +00:00
|
|
|
<ulink url="&url.pgsql;">&url.pgsql;</ulink> and
|
|
|
|
<ulink url="&url.pgsql.techdocs;">&url.pgsql.techdocs;</ulink>.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
2002-08-07 10:01:28 +00:00
|
|
|
</section>
|
|
|
|
|
2002-12-01 17:10:18 +00:00
|
|
|
&reference.pgsql.configure;
|
2002-08-07 10:01:28 +00:00
|
|
|
|
2002-09-14 21:26:46 +00:00
|
|
|
&reference.pgsql.ini;
|
2002-08-07 10:01:28 +00:00
|
|
|
|
|
|
|
<section id="pgsql.using">
|
|
|
|
<title>How to use and hints</title>
|
|
|
|
<warning>
|
|
|
|
<para>
|
|
|
|
Using the PostgreSQL module with PHP 4.0.6 is not recommended due to
|
|
|
|
a bug in the notice message handling code. Use 4.1.0 or later.
|
|
|
|
</para>
|
|
|
|
</warning>
|
|
|
|
<warning>
|
|
|
|
<para>
|
|
|
|
PostgreSQL function names will be changed in 4.2.0 release to
|
|
|
|
confirm to current coding standards. Most of new names will have
|
|
|
|
additional underscores, e.g. pg_lo_open(). Some functions are
|
|
|
|
renamed to different name for consistency. e.g. pg_exec() to
|
|
|
|
pg_query(). Older names can be used in 4.2.0 and a few releases
|
|
|
|
from 4.2.0, but they may be deleted in the future.
|
|
|
|
</para>
|
2002-04-15 00:12:54 +00:00
|
|
|
<table>
|
2002-05-04 10:33:43 +00:00
|
|
|
<title>Function names changed</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
2002-05-04 10:33:43 +00:00
|
|
|
<entry>Old name</entry>
|
|
|
|
<entry>New name</entry>
|
2002-04-15 00:12:54 +00:00
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_cmdtuples</function></entry>
|
|
|
|
<entry><function>pg_affected_rows</function></entry>
|
|
|
|
</row>
|
2003-10-09 13:59:15 +00:00
|
|
|
<row>
|
|
|
|
<entry><function>pg_errormessage</function></entry>
|
|
|
|
<entry><function>pg_last_error</function></entry>
|
|
|
|
</row>
|
2002-04-15 00:12:54 +00:00
|
|
|
<row>
|
2003-10-09 13:55:45 +00:00
|
|
|
<entry><function>pg_exec</function></entry>
|
|
|
|
<entry><function>pg_query</function></entry>
|
2002-04-15 00:12:54 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_fieldname</function></entry>
|
|
|
|
<entry><function>pg_field_name</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_fieldsize</function></entry>
|
|
|
|
<entry><function>pg_field_size</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_fieldnum</function></entry>
|
|
|
|
<entry><function>pg_field_num</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2002-04-25 00:16:22 +00:00
|
|
|
<entry><function>pg_fieldprtlen</function></entry>
|
|
|
|
<entry><function>pg_field_prtlen</function></entry>
|
2002-04-15 00:12:54 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_fieldisnull</function></entry>
|
|
|
|
<entry><function>pg_field_is_null</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_freeresult</function></entry>
|
|
|
|
<entry><function>pg_free_result</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2003-10-09 13:55:45 +00:00
|
|
|
<entry><function>pg_getlastoid</function></entry>
|
|
|
|
<entry><function>pg_last_oid</function></entry>
|
2002-04-15 00:12:54 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loreadall</function></entry>
|
|
|
|
<entry><function>pg_lo_read_all</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_locreate</function></entry>
|
|
|
|
<entry><function>pg_lo_create</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_lounlink</function></entry>
|
|
|
|
<entry><function>pg_lo_unlink</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loopen</function></entry>
|
2002-05-09 08:27:48 +00:00
|
|
|
<entry><function>pg_lo_open</function></entry>
|
2002-04-15 00:12:54 +00:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loclose</function></entry>
|
|
|
|
<entry><function>pg_lo_close</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loread</function></entry>
|
|
|
|
<entry><function>pg_lo_read</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_lowrite</function></entry>
|
|
|
|
<entry><function>pg_lo_write</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loimport</function></entry>
|
|
|
|
<entry><function>pg_lo_import</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_loexport</function></entry>
|
|
|
|
<entry><function>pg_lo_export</function></entry>
|
|
|
|
</row>
|
2003-10-09 13:55:45 +00:00
|
|
|
<row>
|
|
|
|
<entry><function>pg_numrows</function></entry>
|
|
|
|
<entry><function>pg_num_rows</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_numfields</function></entry>
|
|
|
|
<entry><function>pg_num_fields</function></entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><function>pg_result</function></entry>
|
|
|
|
<entry><function>pg_fetch_result</function></entry>
|
|
|
|
</row>
|
2002-04-15 00:12:54 +00:00
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
The old <function>pg_connect</function>/<function>pg_pconnect</function>
|
|
|
|
syntax will be deprecated to support asynchronous connections in the
|
|
|
|
future. Please use a connection string for <function>pg_connect</function>
|
|
|
|
and <function>pg_pconnect</function>.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
</warning>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Not all functions are supported by all builds. It depends on your
|
|
|
|
libpq (The PostgreSQL C Client interface) version and how libpq is
|
|
|
|
compiled. If there is missing function, libpq does not support
|
|
|
|
the feature required for the function.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-11-30 02:10:12 +00:00
|
|
|
It is also important that you do not use an older libpq than the PostgreSQL
|
|
|
|
Server to which you will be connecting. If you use libpq older than PostgreSQL
|
2002-05-04 10:33:43 +00:00
|
|
|
Server expects, you may have problems.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Since version 6.3 (03/02/1998) PostgreSQL uses unix domain sockets
|
|
|
|
by default. TCP port will NOT be opened by default. A table is
|
|
|
|
shown below describing these new connection possibilities. This
|
|
|
|
socket will be found in <filename>/tmp/.s.PGSQL.5432</filename>.
|
|
|
|
This option can be enabled with the '-i' flag to
|
2004-02-28 15:13:46 +00:00
|
|
|
<command>postmaster</command> and its meaning is: "listen on
|
2002-05-04 10:33:43 +00:00
|
|
|
TCP/IP sockets as well as Unix domain sockets".
|
2002-04-15 00:12:54 +00:00
|
|
|
<table>
|
2002-05-04 10:33:43 +00:00
|
|
|
<title>Postmaster and PHP</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<tgroup cols="3">
|
|
|
|
<thead>
|
|
|
|
<row>
|
2002-08-07 10:01:28 +00:00
|
|
|
<entry>Postmaster</entry>
|
|
|
|
<entry>PHP</entry>
|
|
|
|
<entry>Status</entry>
|
2002-04-15 00:12:54 +00:00
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>postmaster &</entry>
|
|
|
|
<entry>pg_connect("dbname=MyDbName");</entry>
|
|
|
|
<entry>OK</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>postmaster -i &</entry>
|
|
|
|
<entry>pg_connect("dbname=MyDbName");</entry>
|
|
|
|
<entry>OK</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>postmaster &</entry>
|
|
|
|
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
|
|
|
|
<entry>
|
|
|
|
Unable to connect to PostgreSQL server: connectDB() failed:
|
|
|
|
Is the postmaster running and accepting TCP/IP (with -i)
|
|
|
|
connection at 'localhost' on port '5432'? in
|
|
|
|
/path/to/file.php on line 20.
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>postmaster -i &</entry>
|
|
|
|
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
|
|
|
|
<entry>OK</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
A connection to PostgreSQL server can be established with the
|
|
|
|
following value pairs set in the command string: <command>$conn =
|
|
|
|
pg_connect("host=myHost port=myPort tty=myTTY options=myOptions
|
|
|
|
dbname=myDB user=myUser password=myPassword ");
|
2002-04-15 00:12:54 +00:00
|
|
|
</command>
|
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
The previous syntax of:
|
2002-04-15 00:12:54 +00:00
|
|
|
<command>
|
2002-05-04 10:33:43 +00:00
|
|
|
$conn = pg_connect ("host", "port", "options", "tty", "dbname")
|
2002-04-15 00:12:54 +00:00
|
|
|
</command>
|
2002-05-04 10:33:43 +00:00
|
|
|
has been deprecated.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Environmental variables affect PostgreSQL server/client
|
|
|
|
behavior. For example, PostgreSQL module will lookup PGHOST
|
|
|
|
environment variable when the hostname is omitted in the connection
|
|
|
|
string. Supported environment variables are different from version
|
|
|
|
to version. Refer to PostgreSQL Programmer's Manual (libpq -
|
|
|
|
Environment Variables) for details.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-05-04 10:33:43 +00:00
|
|
|
Make sure you set environment variables for appropriate user. Use
|
|
|
|
<literal>$_ENV</literal> or <function>getenv</function> to check
|
|
|
|
which environment variables are available to the current process.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<example>
|
2002-05-04 10:33:43 +00:00
|
|
|
<title>Setting default parameters</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<programlisting>
|
|
|
|
<![CDATA[
|
2002-05-20 20:00:45 +00:00
|
|
|
PGHOST=pgsql.example.com
|
2002-04-15 00:12:54 +00:00
|
|
|
PGPORT=7890
|
|
|
|
PGDATABASE=web-system
|
|
|
|
PGUSER=web-user
|
|
|
|
PGPASSWORD=secret
|
|
|
|
PGDATESTYLE=ISO
|
|
|
|
PGTZ=JST
|
|
|
|
PGCLIENTENCODING=EUC-JP
|
|
|
|
|
|
|
|
export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD PGDATESTYLE PGTZ PGCLIENTENCODING
|
|
|
|
]]>
|
2002-08-07 10:01:28 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
2004-07-04 09:10:50 +00:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
PostgreSQL automatically folds all identifiers (e.g. table/column names)
|
|
|
|
to lower-case values. To get it to recognize upper-case values, you must
|
|
|
|
always wrap the identifier in quotes.
|
|
|
|
</para>
|
|
|
|
</note>
|
2002-08-07 10:01:28 +00:00
|
|
|
</section>
|
|
|
|
|
|
|
|
&reference.pgsql.constants;
|
|
|
|
|
|
|
|
<section id="pgsql.examples">
|
|
|
|
&reftitle.examples;
|
|
|
|
<para>
|
|
|
|
Starting with PostgreSQL 7.1.0, you can store up to 1GB into a
|
|
|
|
field of type text. In older versions, this was limited to the block
|
|
|
|
size (default was 8KB, maximum was 32KB, defined at compile time)
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
To use the large object (lo) interface, it is required to enclose
|
|
|
|
large object functions within a transaction block. A transaction
|
|
|
|
block starts with a SQL statement <command>BEGIN</command> and if
|
|
|
|
the transaction was valid ends with <command>COMMIT</command> or
|
|
|
|
<command>END</command>. If the transaction fails the transaction
|
|
|
|
should be closed with <command>ROLLBACK</command> or
|
|
|
|
<command>ABORT</command>.
|
|
|
|
<example>
|
|
|
|
<title>Using Large Objects</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2003-12-15 16:55:22 +00:00
|
|
|
$database = pg_connect("dbname=jacarta");
|
|
|
|
pg_query($database, "begin");
|
|
|
|
$oid = pg_lo_create($database);
|
2002-04-15 00:12:54 +00:00
|
|
|
echo "$oid\n";
|
2003-12-15 16:55:22 +00:00
|
|
|
$handle = pg_lo_open($database, $oid, "w");
|
2002-04-15 00:12:54 +00:00
|
|
|
echo "$handle\n";
|
2003-12-15 16:55:22 +00:00
|
|
|
pg_lo_write($handle, "large object data");
|
|
|
|
pg_lo_close($handle);
|
|
|
|
pg_query($database, "commit");
|
2002-04-15 00:12:54 +00:00
|
|
|
?>
|
|
|
|
]]>
|
2002-08-07 10:01:28 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
You should not close the connection to the PostgreSQL server
|
|
|
|
before closing the large object.
|
|
|
|
</para>
|
|
|
|
</section>
|
2002-04-15 00:12:54 +00:00
|
|
|
</partintro>
|
|
|
|
|
|
|
|
&reference.pgsql.functions;
|
|
|
|
|
|
|
|
</reference>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../../../manual.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|