Skip to Main Content
IBM Power Ideas Portal


This portal is to open public enhancement requests against IBM Power Systems products, including IBM i. To view all of your ideas submitted to IBM, create and manage groups of Ideas, or create an idea explicitly set to be either visible by all (public) or visible only to you and IBM (private), use the IBM Unified Ideas Portal (https://ideas.ibm.com).


Shape the future of IBM!

We invite you to shape the future of IBM, including product roadmaps, by submitting ideas that matter to you the most. Here's how it works:

Search existing ideas

Start by searching and reviewing ideas and requests to enhance a product or service. Take a look at ideas others have posted, and add a comment, vote, or subscribe to updates on them if they matter to you. If you can't find what you are looking for,

Post your ideas
  1. Post an idea.

  2. Get feedback from the IBM team and other customers to refine your idea.

  3. Follow the idea through the IBM Ideas process.


Specific links you will want to bookmark for future use

Welcome to the IBM Ideas Portal (https://www.ibm.com/ideas) - Use this site to find out additional information and details about the IBM Ideas process and statuses.

IBM Unified Ideas Portal (https://ideas.ibm.com) - Use this site to view all of your ideas, create new ideas for any IBM product, or search for ideas across all of IBM.

ideasibm@us.ibm.com - Use this email to suggest enhancements to the Ideas process or request help from IBM for submitting your Ideas.

Status Delivered
Workspace IBM i
Categories Db2 for i
Created by Guest
Created on Oct 31, 2022

UUID datatype for IBMi

A UUID is a Universally Unique Identifier, meaning that these identifiers are unique over your whole DB; even better unique" across space and time". UUID's are stored in 128bit format and follow a standarized format (rfc4122) This makes the type a great alternative to the ID as identity column, I would dare say a superior alternative.


Advantages
  • Easy replications

    • Move data from one system to another

      • Possible because the UUID contains the mac-address of the system. This mac-address should be unique for every system.

      • This makes data-integration between 2 systems effortless

    • Move data from one lib to another

      • The libs are DB2 specific

      • A system where imports between libs are also that easy would be nice. With only UUID's it is still a tedious task. (Similar to the problems we have with ID's now)

  • Generated randomly, impossible to guess the previous/next value

    • Very important in the context of API's since most API protocols expose their unqiue keys in the url.

    • Developers don't have to worry about encrypting/hashing their keys. (Imagine click & print coupons where you could guess the next value...)

  • Supported by almost every respected ORM (sometimes even the default over ID)

  • Add the advantages of regular ID's to this list...

What would the UUID implementation look like? (Pseudocode)
Solution similar to the id:

CREATE OR REPLACE TABLE USERS (
uuid uuid not null generated always as identity,
firstname varchar(50) not null,
lastname varchar(50) not null

primary key (uuid)
);

An alternative would be to combine GENERATED ALWAYS with DEFAULT GENERATE_UUID():
CREATE OR REPLACE TABLE USERS (
uuid varchar(50) generated always default GENERATE_UUID(),
firstname varchar(50) not null,
lastname varchar(50) not null

primary key (uuid)
);

My least favorite alternative is provide a default so applications don't have to pass the value every time. But it allows invalid userinput:
CREATE OR REPLACE TABLE USERS (
uuid varchar(50) not null default GENERATE_UUID(),
firstname varchar(50) not null,
lastname varchar(50) not null

primary key (uuid)
);

Note: It seems like we can't use scalar functions like GENERATE_UNIQUE() as default value today. Is this material for a separate ticket?


Workarounds/Alternatives (See attached SQL files to play with it yourself)

Rowid

GUID/UUID identity support

Support for UUID columns

CREATE OR REPLACE TABLE USERS  (

rid rowid generated always,
firstname varchar(50) not null,
lastname varchar(50) not null
);

insert into users (firstname, lastname)
values ('Mario', 'Aquino'), ('Dimi', 'VLH');

-- Does NOT work => only one rowid/table allowed
CREATE OR REPLACE TABLE ADDRESSES (
rid rowid generated always,
street varchar(50),
city varchar(50),
user_id rowid,

foreign key (user_id) REFERENCES users(rid)
);

-- Does not work because the types are not compatible?
CREATE OR REPLACE TABLE ADDRESSES (
rid rowid generated always,
street varchar(50),
city varchar(50),
user_id varchar(26),

foreign key (user_id) REFERENCES users(id)
);
  • No primary-/foreign-key constraints possible

  • Does not work (maybe with some complex casting?)

Triggers

CREATE OR REPLACE TABLE USERS  (

uuid varchar(13) not null,
firstname varchar(50) not null,
lastname varchar(50) not null,

primary key (uuid)
);

CREATE OR REPLACE TRIGGER generate_uuid AFTER INSERT ON USERS FOR EACH ROW MODE DB2SQL UPDATE USERS SET UUID = GENERATE_UNIQUE();

insert into users (uuid, firstname, lastname)
values ('tempstring', 'Mario', 'Aquino'), ('tempstring2', 'Dimi', 'VLH');

select *
from users;
  • SQL adapters in Open Source Languages will have to check if the trigger exists before every insert operation.

  • On insert we have to send dummydata in the table as a placeholder before the trigger is executed. For an identity column it becomas a daunting task to provide unique dummydata.

Alternative with SQL Sequence Object

CREATE OR REPLACE TABLE USERS  (

uuid integer not null,
firstname varchar(50) not null,
lastname varchar(50) not null,

primary key (uuid)
);

CREATE OR REPLACE SEQUENCE unique_identifiers AS INTEGER
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO CYCLE
CACHE 20;

-- Does not work, because the uuid is not generated
insert into users (firstname, lastname)
values ('Mario', 'Aquino'), ('Dimi', 'VLH');

insert into users (uuid, firstname, lastname)
values (next value for unique_identifiers, 'Mario', 'Aquino'), (next value for unique_identifiers,'Dimi', 'VLH');

select *
from users;
  • External users can guess the next key (still just incrementing numbers)

  • SQL adapters in Open Source languages will have to check if this sequence exists before every insert.

What about other databases?

Postgresql has great support for this column type.

MySQL and SQLite stumble behind, but their connector-packages provide support from within the OpenSource languages. I'm not a fan of this approach since you have to translate the logic to every language...


Recap

I know there have been tickets opened about this before. But today we still don't have proper working workarounds, are they are too much work to implement and maintain.

UUID's appear more and more into modern implementations because it guaranties easier integration in future systems because you can use the existing identifiers. No need to create mapping between identifiers from system A to system B!

Idea priority Medium
  • Guest
    Reply
    |
    Dec 13, 2024
    IBM will not a new data type due to the high cost of implementation.

    Instead, we have provided two new built-in scalar functions to generate Version 4 UUID values. One produces the 16 byte internal form and the other the formatted string version.

    See these IBM Documentation pages for the details:
    https://www.ibm.com/docs/en/i/7.5?topic=functions-generate-uuid
    https://www.ibm.com/docs/en/i/7.5?topic=functions-generate-uuid-binary

    This enhancement was delivered in December 2024 with IBM i 7.5 Database PTF Group level 8 and IBM i 7.4 Database PTF Group level 29.

    Db2 for i development team
    IBM Power Systems Development
  • Guest
    Reply
    |
    Jul 30, 2024

    UUID version 4 is great, but see also version 7 and version 8, both recently introduced but perhaps not yet fully finalized. They have the advantage of better access path paging as newly generated values will fall on the same or nearby access path pages as valued just previously generated.

    1 reply
  • Admin
    Carmelita Ruvalcaba Cevallos
    Reply
    |
    Apr 23, 2024

    The CAAC has reviewed this IBM Idea and recommends that IBM view this as a medium priority Idea that should be addressed.

    We recommend that the version 4 be adopted if this is implemented. We believe making this an SQL function is advantageous.

    Background: The COMMON Americas Advisory Council (CAAC) members have a broad range of experience in working with small and medium-sized IBM i customers. CAAC has a key role in working with IBM i development to help assess the value and impact of individual IBM Ideas on the broader IBM i community and has therefore reviewed your Idea.

    For more information about CAAC, see www.common.org/caac

    Carmelita Ruvalcaba - CAAC Program Manager

  • Guest
    Reply
    |
    Nov 10, 2022
    IBM will use this Idea as input to planning, but no commitment is made or implied. This Idea will be updated in the future if IBM implements it.
  • Guest
    Reply
    |
    Nov 10, 2022

    Thank you so much for this! You have clearly invested some time going through my examples and also in creating this workaround.

    In my opinion, a function like this should be added by default in DB2 SQL. Like this you don't have to repeat this for every client/library.

    Something similar concerning the trigger. It is a great touch to my post to add the trigger before insert instead of after! But I don't get why there does not exist something like:

    uuid varchar(16) not null default GENERATE_UUID_AS_STRING()

    Imagine having a seperate type, like that we could have a generated always:
    uuid uuid generated always (using GENERATE_UUID_AS_STRING() under the hood)


  • Guest
    Reply
    |
    Nov 8, 2022

    The documentation for GENERATE_UNIQUE contains an example for a BEFORE INSERT trigger that doesn't require a dummy value. Whatever the GENERATE_UNIQUE returns doesn't seem to be an UUID considering that it only returns 13 instead of 16 bytes.

    I've put together a short example with some UUID functions that might be helpful.

  • Guest
    Reply
    |
    Oct 31, 2022

    Sorry about the spaces in the SQL examples. No idea why this happened. Previous time when I fixed it in the edit, my ticket was gone. So I'm leaving it like this.

2 MERGED

UUID datatype for IBMi

Merged
A UUID is a Universally Unique Identifier, meaning that these identifiers are unique over your whole DB, even better unique" across space and time". UUID's are stored in 128bit format and follow a standarized format (rfc4122) This makes the type a...
about 2 years ago in IBM i / Db2 for i 1 Delivered