Home > database >  AUTO INCREMENT char and integer in same column
AUTO INCREMENT char and integer in same column

Time:10-28

i have a table with an id as primary key

CREATE TABLE "societe" (
    "id"    INTEGER UNIQUE,
    "name"  TEXT,
    "phone" INTEGER,
    PRIMARY KEY("id" AUTOINCREMENT)
);

I want the "ID" to be auto increment but i want it in this format:

"C1", "C2", "C3", ...

any help please ?

CodePudding user response:

You can simply use your auto increment id column to output according to desired output:

SELECT "C"||id from societe;

Which simply concatenates the desired character and the value from idcolumn, with the help of the || concateneation operator.

After a few insert lines (missing from your mre), the output is:

C0
C1
C2
C3
C4
C5
C6
C7
C8
C9
C10
C11

e.g. here https://sqliteonline.com

  • Related