The Rookie Rides Again - Creating UUID key fields

Hi,

After viewing some material from Servoy University, I’m working towards changing the primary keys in my database to be UUID rather than integer keys. I’m not able to make those changes within Servoy, so I am using pgAdmin to attempt this. pgAdmin will not let me change the field type from integer to uuid, so I am deleting the field and recreating it and at that point giving it a data type of uuid, then creating the primary key constraint within pgAdmin. When I come back to Servoy 5.2.2 and do a reload of the database, the type field for the primary key field says “Unknown type #1111”. If I mouse over the type field, I get a message “AE: Sequence Value, universally unique identifier”. I am able to change the sequence type to be “uuid generator”. I have a length of 16 and a row ident of “pk”. Since pgAdmin has many more data types available than Servoy, I’m wondering if the field should be created a different way in order to better match what Servoy has available in order to avoid the “unknown type” message.

As always, any assistance would be greatly appreciated.

Thanks and have a good day.

Ron

Why are you changing the primary keys to be UUID rather than integer keys? Can you enlighten me? – just for pure curiosity ;-)

Hi Ron,

PostgreSQL comes with an extension (contrib) that gives PostgreSQL a UUID datatype (which will be a binary type), but you can also store UUID’s as VARCHAR(26).
This last datatype is way more compatible with other SQL vendors so if you want to be able to deploy your solution to those SQL vendors as well you might want to go that route.
But Carlos is asking a legitimate question. Why the UUID’s instead of Integers. Integers are much lighter than UUID’s in many ways (joins, indices, etc.).
There are only a few cases why it would make sense to choose a UUID over an Integer for your PK’s.

Edit: that should be VARCHAR(36)
Edit2: Okay, I was misinformed. PostgreSQL HAS a UUID datatype built in, the contrib is to generate UUID’s. Which of course Servoy already does for you.

Hi,

Well, there are a couple of reasons that I think UUIDs are a better solution for me. But remember, of course, being a rookie, that I could be deluding myself, but the answers that I received from the Servoy U folks (and some discussion with my Servoy mentor) made sense. So, here goes…

In a standard multi-tenant environment being supported on a single server, integer keys are just fine. However, if the application has the potential to grow to multiple servers or make use of other types of distributed systems, then UUIDs eliminate any possibility of duplicate key problems. With that in mind…

My application is currently distributed as a Microsoft Access runtime app. As part of the move to Servoy, I’ll have the ability to distribute the app both as a web application with a shared database, and as a runtime with it’s own copy of the database. That creates at least the potential for duplicate keys if the owner of a runtime version decides to move over to the web application (which is what I hope every one of them will do). There are a couple of ways to handle this. One, I could create a “dummy key” of sorts in the web application whenever I sell a runtime version of the app, effectively reserving that primary key for later use if needed. Or, I could use UUIDs, in which case I always have unique keys.

Also, I have on the drawing board a number of new applications that have the potential to share information from my existing app. Although those are a still “a gleam in my mind’s eye”, I can foresee sharing information from one app to another, and using UUIDs gives me a unique key that is consistent across all of my applications, so I can move information from one system to another without having to worry about identifying information by combinations of name, address, etc.

For example, my current application supports artists on the business side of their art. It’s primarily meant to be single user application. I will be adding, say, a studio version of the software, and in that software, an artist could be a part of a studio, and would have created their art information there. They could later decide that they’d like to use one of my other products, and by having unique keys across applications, they could simply migrate their information from one system to another (I’m creating a standard protocol to allow the apps to talk to each other).

And, in my more delusional moments, I see a time when I might be so successful that I’ll need to run the apps on multiple servers. That, I’m told, is a good use of UUID keys.

So, there you have it. I’m certainly open to other thoughts, since I don’t consider myself anything approaching competent yet. This seemed like a reasonable approach. Now, the folk at Servoy U that I traded a couple of messages with didn’t seem to believe that the overhead from using UUIDs was anything to be overly concerned about, but I suppose that’s all relative.

Lastly, yes, I have had a couple of Servoy folks tell me that using the runtime is akin to dealing with the anti-Christ (actually, what they said was more like “it’s not our preferred method of distribution” :-)). For now, I can’t assume that my existing customer base are all going to come running to the web app, and so I have to account for that. In the long run, I’d like to have them all on the web app, but for now, I have a lot of flexibility.

Thanks again for your thoughts. Appreciate it.

Ron

Robert, thanks for the information on storage of UUIDs. I’ll try that to see if it eliminates the message I’m getting in Servoy.

Have a good day.

Ron

Hi,

I went into pgAdmin and as a test, created a new field with type Character Varying with a length of 26. I then created a constraint, using the new field as the primary key. I then went into Servoy and reloaded the database. Servoy interpreted the new field as a Text field with a length of 26, and recognized it as “pk” as well. Servoy also allowed me to use the 'uuid generator" on that field. So, the warning message I received has been eliminated, and this does appear to work, at least as far as designing the table is concerned.

That’s the latest on my end.

Thanks again.

Ron

Hi Ron,

My mistake, that should be a VARCHAR(36), not 26.

Ron,

You can also use bytea column type.
In that case Servoy will store the UUIDs as 16-byte arrays.

Rob

Hi Rob,

Thanks. Is there any difference as far as Servoy is concerned? Let’s say as it relates to application development rather than internals.

Ron

No, internally both are treated as UUIDs.
In scripting you will get the UUID object, independent of the storage type.

Rob

Rob,

Would Servoy (I haven’t tested this yet) support the (already built in) PostgreSQL uuid datatype ?
http://www.postgresql.org/docs/9.0/stat … -uuid.html

Hi Robert,

Using the Postgresql uuid data type is what I tried earlier. Servoy returns a warning message for that. However, if you use the data types suggested above, the warning message does not appear and you’re able to use the uuid generator within Servoy.

Ron

Robert,

Apparently the postgres driver gives us Unknown type 1111 (which in Types.OTHER in jdbc), we can’t do something with that.

Rob