postgresql - How to auto increment id with a character -


how auto-increment id of member in table character example: m_01, m_02, m_03:

create table company(    id int primary key     not null,    name           text    not null,    age            int     not null,    address        char(50),    salary         real ); 

the answer is: don't.

use basic serial column. can format column on output.
sensible table definition (added more suggestions):

create table company(     company_id serial primary key   , birth_year int    not null   , company    text   not null   , address    text   , salary     int            -- in cents ); 

then:

select to_char(companyid, '"m_"fm00000')  -- produces m_00001 etc.   company; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -