0

I have dictionary_type and dictionary_value tables. Value is connected with type. I would like to create sequence which will set the id of values according to type id.

Expected dictionary_type:

id       type     
----     ---- 
1        type1       
2        type2           

Expected dictionary_value:

id       type_id     value
-------  -------  -------
100      1         value1
200      2         value2
101      1         value3
102      1         value4
201      2         value5

So baiscly I would like to make it like: nextval(sequence(type_id * 100)). How can I do it in postgresql?

Have a nice day!

Tom
  • 1

1 Answers1

0

If I understand correctly you want to have ids that depend on another column. I'm sorry not to answer your question, because I don't understand that need. Why would you need that ?

The only purpose of a sequence is giving unique values. What's wrong with that kind of data?

id       type_id     value
-------  -------  -------
1        1         value1
2        2         value2
3        1         value3
4        1         value4
5        2         value5

If your problem is that you want to be able to sort your data by type_id and then by id, just try that query :

select id,
  type_id,
  value
from my_table
order by type_id, id
Arkhena
  • 1,610
  • 10
  • 15