Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Started using UUID's as primary key, would like to execute union of entities with BigSerial Primary Key

$
0
0

Some of my newer tables are now using UUID type fields as PKey and older tables are still using bigserial. I have several tables (let’s call them entities) I would like to query returning the primary key in the result (using a UNION). What is the most efficient way to return the entity_id’s? I am assuming a simple CAST would do the trick, but this is to handle a sitewide search which requires it to be as quick as possible.

    select entityA.a_id::TEXT as entity_id from entityA
    union
    select entityB.b_uuid::TEXT as entity_id from entityB
    union
    select entityC.c_id::TEXT as entity_id from entityC
    union
    select entityD.d_id::TEXT as entity_id from entityD
    union
    select EntityE.e_id::Text as entity_id from EntityE

Any recommendations?


Viewing all articles
Browse latest Browse all 1138

Trending Articles