I want (for some reason) to store data as a bytea (binary blob, let's say it's a C struct memory dump, or an ASN.1 encoded record, as dumb and a bad idea as it sounds) and allow access to it via a user-defined types (coded in C, calling the deserialiser, filling the UDT fields).
I'd like to keep them (bytea and UDT) in the same table or at least to be able to access the data in both ways (through the original bytea, and through the UDT). And I'd like the UDT not to take space (I want it to be deserialised from the bytea anytime it is accessed).
For example I'd declare a simple 2-column table : (bytea, my_udt). How can I implement the UDT so it knows it's backed by the bytea field? Or other option, if I create just one table with the bytea, then is it possible to create a view from the bytea, allowing access to the bytea AND the UDT extracted on-the-fly when needed (but doesn't take disk space)?
Is it possible at all? How should I proceed?