I have a Postgres database with about 35 tables of varying sizes. Every table has an auto incrementing integer primary key, as well as a column of native Postgres uuid
data type recording Version 4 UUID values.
The application code logs UUIDs, but…alas…doesn't always log the object type or table.
While we're working on cleaning that up, we sometimes just want to figure out what row a UUID refers to.
Is there a reasonable strategy to create a view, index, or even full on table to efficiently find a row given a UUID, if every row in the database has a UUID? Or am I chasing an antipattern and should solve it at the application level?
Best Answer
Disclaimer: I think the whole idea doesn't really make sense. But anyway here is one way to get a uniform "view" on all UUIDs in the database.
You can create a function that goes through all columns that are defined as UUID and then returns the values for those columns. You can optionally pass a UUID value that should be searched for:
Something like:
Then you can use:
to find the tables where that UUID value appears, or
to see everything.
The above returns something like this:
But this is going to be really slow