Chapter 9. PostgreSQL™ Extensions to the JDBC API

PostgreSQL™ is an extensible database system. You can add your own functions to the server, which can then be called from queries, or even add your own data types. As these are facilities unique to PostgreSQL™, we support them from Java, with a set of extension API's. Some features within the core of the standard driver actually use these extensions to implement Large Objects, etc.

To access some of the extensions, you need to use some extra methods in the org.postgresql.PGConnection class. In this case, you would need to case the return value of Driver.getConnection(). For example:

Connection db = Driver.getConnection(url, username, password);
// ...
// later on
Fastpath fp = ((org.postgresql.PGConnection)db).getFastpathAPI();

public class PGConnection 

These are the extra methods used to gain access to PostgreSQL™'s extensions.

public class Fastpath extends Object

java.lang.Object
   |
   +----org.postgresql.fastpath.Fastpath

Fastpath is an API that exists within the libpq C interface, and allows a client machine to execute a function on the database server. Most client code will not need to use this method, but it is provided because the Large Object API uses it.

To use, you need to import the org.postgresql.fastpath package, using the line:

import org.postgresql.fastpath.*;
Then, in your code, you need to get a FastPath object:
Fastpath fp = ((org.postgresql.PGConnection)conn).getFastpathAPI();
This will return an instance associated with the database connection that you can use to issue commands. The casing of Connection to org.postgresql.PGConnection is required, as the getFastpathAPI() is an extension method, not part of JDBC. Once you have a Fastpath instance, you can use the fastpath() methods to execute a server function.

See Also:  FastpathFastpathArg, LargeObject