Class 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.

    • Method Detail

      • modIn

        @Function(schema="javatest",
                  name="intwithmod_typmodin",
                  effects=IMMUTABLE,
                  onNullInput=RETURNS_NULL)
        public static int modIn​(@SQLType("pg_catalog.cstring[]")
                                String[] toks)
                         throws SQLException
        Type modifier input function for IntWithMod type: accepts "even" or "odd". The modifier value is 0 for even or 1 for odd.
        Throws:
        SQLException
      • modOut

        @Function(schema="javatest",
                  name="intwithmod_typmodout",
                  type="pg_catalog.cstring",
                  effects=IMMUTABLE,
                  onNullInput=RETURNS_NULL)
        public static String modOut​(int mod)
                             throws SQLException
        Type modifier output function for IntWithMod type.
        Throws:
        SQLException
      • modApply

        @Function(schema="javatest",
                  name="intwithmod_typmodapply",
                  effects=IMMUTABLE,
                  onNullInput=RETURNS_NULL)
        @Cast(comment="Cast that applies/verifies the type modifier on an IntWithMod.",
              provides="IntWithMod modCast")
        public static IntWithMod modApply​(IntWithMod iwm,
                                          int mod,
                                          boolean explicit)
                                   throws SQLException
        Function backing the type-modifier application cast for IntWithMod type.
        Throws:
        SQLException