Re: how to generate a list of distinct scalar values from a column which type is array
В списке pgsql-general по дате отправления:
| От | David Fetter |
|---|---|
| Тема | Re: how to generate a list of distinct scalar values from a column which type is array |
| Дата | |
| Msg-id | 20070222165648.GE10321@fetter.org обсуждение исходный текст |
| Ответ на | how to generate a list of distinct scalar values from a column which type is array ("Sergio Andreozzi" <sergio.andreozzi@gmail.com>) |
| Список | pgsql-general |
On Thu, Feb 22, 2007 at 12:38:50PM +0100, Sergio Andreozzi wrote:
> Dear all,
>
> given a column which type is for instance varchar(20)[],
This is almost never a good design. If you must have an interface
like that, make it VIEW over an aggregate, which you can make
writeable.
> is it possible via SQL to generate the list of distinct scalar
> values?
Yes, but you should fix your design :)
CREATE TABLE foo (ft TEXT[]);
COPY foo(ft) FROM stdin;
{aaa,bb,c}
{dddd,eeee}
{aaa,eeee}
\.
SELECT DISTINCT ft[i]
FROM (
SELECT ft,
generate_series(
array_lower(ft,1),
array_upper(ft,1)
) AS i
FROM foo
) AS bar;
So, yes, you can do it, and no, you shouldn't.
Cheers,
D
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter
Remember to vote!
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера