Добавить неупорядоченный список элементов в базе данных? - PullRequest
0 голосов
/ 01 ноября 2019

Я пытаюсь создать таблицу строкового содержимого, содержащую несколько столбцов, некоторые из которых включают (маркированный) неупорядоченный список. Считается ли это списком значений, массивом или чем-то еще? Это пример:

|----|----------------------|----------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| 1 | Transition Age Youth | • Wrap-around services • Case management • Voluntary residential services • Employment and permanent housing support | • Outreach and engagement  • Telemedicine  • Counseling and services |```

Is this as simple as using line breaks /n or /r/n in the data itself? 

I'll be using this as an open-data directory of services. I intend to have a search function where people can find all records containing keywords they specify. There's about 10 more columns I'm not showing which would help others narrow by filtering rows. 

Thank you for any insight. 

[!This photo illustrates one of several tables. Some have multiple unordered lists, this one illustrates a single list. There may be a limited list of options if that would help knowing too.[1]][1]


  [1]: https://i.stack.imgur.com/MaTmV.png

1 Ответ

0 голосов
/ 01 ноября 2019

Значения, разделенные маркером (или любым разделителем текста), обычно представляют собой ненормализованные данные, и вам следует избегать их хранения в вашей базе данных. Я предлагаю следующий дизайн:

id | idx | desc
1  | 1   | Prevent re-institutionalization and homelessness;
1  | 2   | Transition Age Youth
1  | 3   | Wrap-around services
1  | 4   | Case management
1  | 5   | Voluntary residential services

Если вы хотите создать разделенный маркерами список, просто используйте функцию Postgres 'string_agg:

SELECT
    id, 
    string_agg(desc, '•' order by idx) as list
FROM your_table
GROUP BY
    id;
...