pljava
pljava
pljava : PL/Java procedural language
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3090 | pljava
|
pljava
|
1.6.10 |
LANG
|
BSD 3-Clause
|
Java
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d--
|
No
|
Yes
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| Schemas | sqlj |
| See Also | plpgsql
plv8
plperl
plpython3u
pg_tle
pllua
plluau
pltclu
|
missing debian/ubuntu pg18
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG
|
1.6.10 |
18
17
16
15
14
|
pljava |
- |
| RPM | PGDG
|
1.6.10 |
18
17
16
15
14
|
pljava_$v |
- |
| DEB | PGDG
|
1.6.9 |
18
17
16
15
14
|
postgresql-$v-pljava |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
el8.aarch64
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
el9.x86_64
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
el9.aarch64
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
el10.x86_64
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
el10.aarch64
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
PGDG 1.6.10
|
d12.x86_64
|
MISS
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
d12.aarch64
|
MISS
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
d13.x86_64
|
MISS
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
d13.aarch64
|
MISS
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
u22.x86_64
|
MISS
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
u22.aarch64
|
MISS
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
u24.x86_64
|
MISS
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
u24.aarch64
|
MISS
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
PGDG 1.6.9
|
| Package | Version | OS | ORG | SIZE | File URL |
|---|---|---|---|---|---|
pljava_18 |
1.6.10 |
el8.x86_64 | pgdg | 927.7 KiB | pljava_18-1.6.10-1PGDG.rhel8.x86_64.rpm |
pljava_18 |
1.6.10 |
el8.aarch64 | pgdg | 923.4 KiB | pljava_18-1.6.10-1PGDG.rhel8.aarch64.rpm |
pljava_18 |
1.6.10 |
el9.x86_64 | pgdg | 917.4 KiB | pljava_18-1.6.10-1PGDG.rhel9.x86_64.rpm |
pljava_18 |
1.6.10 |
el9.aarch64 | pgdg | 914.2 KiB | pljava_18-1.6.10-1PGDG.rhel9.aarch64.rpm |
pljava_18 |
1.6.10 |
el10.x86_64 | pgdg | 918.3 KiB | pljava_18-1.6.10-1PGDG.rhel10.x86_64.rpm |
pljava_18 |
1.6.10 |
el10.aarch64 | pgdg | 914.7 KiB | pljava_18-1.6.10-1PGDG.rhel10.aarch64.rpm |
Source
Install
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install pljava; # install via package name, for the active PG version
pig install pljava -v 18; # install for PG 18
pig install pljava -v 17; # install for PG 17
pig install pljava -v 16; # install for PG 16
pig install pljava -v 15; # install for PG 15
pig install pljava -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pljava;Usage
pljava enables writing PostgreSQL functions, triggers, and types in Java using the standard JDBC API.
CREATE EXTENSION pljava;Deploy Java Code
Package your Java classes in a JAR file with an SQLJ deployment descriptor, then install it:
SELECT sqlj.install_jar('file:///path/to/my_functions.jar', 'myjar', true);
SELECT sqlj.set_classpath('public', 'myjar');Create Functions
Write a Java class with static methods:
package com.example;
import org.postgresql.pljava.annotation.Function;
public class MyFunctions {
@Function
public static int add(int a, int b) {
return a + b;
}
@Function
public static String hello(String name) {
return "Hello, " + name + "!";
}
}Declare the SQL function mapping:
CREATE FUNCTION add(int, int) RETURNS int
AS 'com.example.MyFunctions.add'
LANGUAGE java;
CREATE FUNCTION hello(varchar) RETURNS varchar
AS 'com.example.MyFunctions.hello'
LANGUAGE java;Set-Returning Functions
Implement ResultSetProvider for set-returning functions:
import org.postgresql.pljava.ResultSetProvider;
import java.sql.ResultSet;
import java.sql.SQLException;
public class MySetFunction implements ResultSetProvider {
public boolean assignRowValues(ResultSet receiver, int currentRow)
throws SQLException {
if (currentRow < 10) {
receiver.updateInt(1, currentRow);
receiver.updateString(2, "row " + currentRow);
return true;
}
return false;
}
public void close() {}
public static ResultSetProvider generate()
throws SQLException {
return new MySetFunction();
}
}Trigger Functions
import org.postgresql.pljava.TriggerData;
import org.postgresql.pljava.annotation.Trigger;
public class MyTrigger {
@Trigger(called = Trigger.Called.BEFORE, table = "my_table",
events = {Trigger.Event.INSERT, Trigger.Event.UPDATE})
public static void auditTrigger(TriggerData td) throws SQLException {
ResultSet newRow = td.getNew();
newRow.updateTimestamp("modified_at",
new java.sql.Timestamp(System.currentTimeMillis()));
}
}Database Access via JDBC
import java.sql.*;
public static int countUsers() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement stmt = conn.prepareStatement("SELECT count(*) FROM users");
ResultSet rs = stmt.executeQuery();
rs.next();
return rs.getInt(1);
}JAR Management
SELECT sqlj.install_jar('file:///path/to/jar', 'jarname', true);
SELECT sqlj.replace_jar('file:///path/to/new.jar', 'jarname', true);
SELECT sqlj.remove_jar('jarname', true);
SELECT sqlj.set_classpath('schemaname', 'jar1:jar2');
SELECT sqlj.get_classpath('schemaname');Last updated on