Class IntWithMod

java.lang.Object
org.postgresql.pljava.example.annotation.IntWithMod
All Implemented Interfaces:
SQLData

@SQLAction(requires="IntWithMod modCast", install="SELECT CAST(\'42\' AS javatest.IntWithMod(even))") @BaseUDT(schema="javatest", provides="IntWithMod type", typeModifierInput="javatest.intwithmod_typmodin", typeModifierOutput="javatest.intwithmod_typmodout", like="pg_catalog.int4") public class IntWithMod extends Object implements SQLData
An integer-like data type accepting a type modifier: IntWithMod(even) or IntWithMod(odd).

Support for type modifiers in PL/Java is only partial so far. It does not yet honor typmods passed to the input/receive functions ... but it may be that only COPY operations require that. Most uses of types with modifiers seem to pass -1 when first constructing the value, then use a typmod- application cast, and all of that can be done in PL/Java already.

Serving suggestion:

 CREATE TABLE evod (
   ev javatest.IntWithMod(even),
   od javatest.IntWithMod(odd)
 );
 INSERT INTO evod ( ev, od ) VALUES ( '4', '7' );

Of course this example more or less duplicates what you could do in two lines with CREATE DOMAIN. But it is enough to illustrate the process.