Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I want to add a function to particular column while creating a table in PostgreSQL. After creating table, it has to generate auto generated id when we insert values into to the table.

share|improve this question
1  
What do you mean by auto generated id? –  Mladen Uzelac Jul 11 at 10:27

1 Answer 1

There is serial and bigserial numeric type to autogenerate numbers i.e. autoincrement.
If you want to have custom function then you need to create trigger functions first and assign it to the trigger on insert.

More in the postgresql docs:
http://www.postgresql.org/docs/9.4/static/datatype-numeric.html

share|improve this answer
    
is that function can generate id after adding function to that column and how to define function to that column –  haider Jul 11 at 8:35
    
what kind of id do you want to insert. Function is not added to column, it is added to trigger. And every time you run insert, that function is run. And that the value created in the function is added to the column. –  Mladen Uzelac Jul 11 at 10:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.