HybridDB for PostgreSQL supports compiling and uploading JAR software packages written in PL/Java languages, and using these JAR packages to create user-defined functions (UDF). The PL/Java language supported in this feature is Community Edition PL/Java 1.5.0 and the JVM version is 1.8.
In HybridDB for PostgreSQL, run the following command to create a PL/Java plug-in. The command only needs to be ran once for the database.
create extension pljava;
Compile the UDF based on your business requirements. For example, you can use the following code to compile the
public class Test
public static String substring(String text, int beginIndex,
return text.substring(beginIndex, endIndex);
Build-Date: 01/20/2016 21:00 AM
Run the following command to compile and package the program.
jar cfm analytics.jar manifest.txt Test.class
analytics.jarfile generated in Step 4 to the OSS by using the following OSS console command.
osscmd put analytics.jar oss://zzz
In HybridDB for PostgreSQL, run the “Create Library” command to import the file to HybridDB for PostgreSQL.
Note: The “Create Library” command only supports filepath and you can import one file a time. In addition, the “Create Library” command also supports byte streams to directly import files without using the OSS. For more information, see Use the Create Library Command.
create library example language java from 'oss://oss-cn-hangzhou.aliyuncs.com filepath=analytics.jar id=xxx key=yyy bucket=zzz';
In HybridDB for PostgreSQL, run the following command to create and use the UDF.
create table temp (a varchar) distributed randomly;
insert into temp values ('my string');
create or replace function java_substring(varchar, int, int) returns varchar as 'Test.substring' language java;
select java_substring(a, 1, 5) from temp;