Sample Header Ad - 728x90

Inserting a Hyphen in between a composite primary key

1 vote
2 answers
73 views
I have more of a conceptual question. Is there a way to model the following:
CREATE TABLE AssetPair (
      older_asset_id INT8,
      newer_asset_id INT8,
      PRIMARY KEY (older_asset_id, '-', newer_asset_id)
  );
My issue is that older_asset_id and newer_asset_id are incrementing IDs so the following edgecases are possible:
older_asset_id: 1, newer_asset_id: 234 --> PrimaryKey:1234
// same Primary keys
older_asset_id: 12 newer_asset_id: 34 --> PrimaryKey:1234
If I was able to insert a hyphen between the two columns I'd be able to avoid this issue. Any thoughts?
Asked by Eric Sharma (13 rep)
Feb 15, 2024, 10:03 PM
Last activity: Feb 16, 2024, 02:01 PM