I have many lines of existing data which seems to use a unique identifier column that begins with the letter K and is followed by 8 or 9 random numbers. I would like to use this column as the primary key in a table. For all future additions to the table I'd like to automatically generate a unique PK that follows the same format as the existing data. Is there a way to achieve this within SQL code, or would I need to create an elaborate (for my beginner level) Python function that generates the unique PK?

1

There are 1 best solutions below

4
On

I would leave the existing rows as they are and continue with a different scheme for future rows, for example a plain number without letter (cast to a string). That can be generated with a sequence conveniently, and there is no risk of collisions.

Simplicity over perceived beauty!