sql - Reproduce certain rows in PostgreSQL -


i have table ids represent individuals (call id_table) , table characteristics individual can have (call char_table).

now want add column id_table containing values char_table. difficulty, me, is, id shall 1 characteristic (simple case) , id shall several characteristics. reason rows these id several characteristics must reproduced until have matched every characteristic id. example: id '001' shall characteristics 'a', 'b', , 'c'. row id='001' must reproduced 2 times (to same row 3 times) , each of these rows shall 1 of these 3 characteristics.

i hope explained intelligible enough. idea how this? thanks.

in cases, want association or junction table. table like:

create table individualcharacteristicsr (     individualid int not null,     characterid int not null ); 

(it might have unique id itself.)

each characteristic individual has on separate row. so, 3 characteristics mean 3 rows. typical query using information join 3 tables:

from id_table left outer join      individualcharacteristicsr ic      on i.individualid = ic.individualid left outer join      char_table c      on c.characteristicid = ic.characteristicid 

(the left outer join includes individuals no characteristics.)

in postgres, store characteristics in string or array. neither convenient joining id_char. better approach additional table.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -