db2comparesqldatatypesoidobject-relational-model

OID comparison in IBM DB2


I'm trying to use object oriented features of DB2 for the first time. I've created types, typed tables and inserted data. The problem is I can't compare user generated OIDs.

My type:

CREATE TYPE "orschema"."pojistovna_typ" AS(
nazev VARCHAR(30), 
cislo VARCHAR(3))
INSTANTIABLE
REF USING INTEGER
MODE DB2SQL;

My typed table:

CREATE TABLE "orschema"."pojistovna" OF "orschema"."pojistovna_typ"
(REF IS oid USER GENERATED);

Succesfully inserted data with command:

INSERT INTO "orschema"."pojistovna" (oid, nazev, cislo)
  VALUES("orschema"."pojistovna_typ"(1), 'ccc', '105');

But this SELECT doesn't work at all, but in IBM knowledge is it done the same way:

SELECT * FROM "orschema"."pojistovna" AS "p"
WHERE "p"."oid" = "orschema"."pojistovna_typ"(1);

ERROR: data types are not compatible or not comparable with "="


Solution

  • One way to do it is using CAST funcion, but I'm not sure if this won't slow down this query:

    SELECT * FROM "orschema"."pojistovna" AS "p" WHERE CAST("p".oid AS INTEGER) = 1;