Converting an hstore into a key/value record

Поиск
Список
Период
Сортировка
От Jon Smark
Тема Converting an hstore into a key/value record
Дата
Msg-id 486393.91832.qm@web112814.mail.gq1.yahoo.com
обсуждение исходный текст
Список pgsql-general
Hallo,

Suppose I have the following 'scores_t' record:

  create type scores_t as (item text, score int);

What's the cleanest way of converting a hstore into a set of scores_t,
with each key mapping to field 'item', and the value to field 'score'?

As an example, consider the following (non-working) code:

  create table people (id int4 unique not null, scores hstore);

  create function get_scores (int4)
  returns setof scores_t
  language sql stable as
  $$
        select each (scores) from people where id = $1;
  $$

Sure, I could cook up some PL/pgSQL to do this task, but I suspect
there must be some much simpler SQL statement that does the same...

Thanks in advance!
Jon


В списке pgsql-general по дате отправления:

Предыдущее
От: Nick Raj
Дата:
Сообщение: Pl/pgsql function
Следующее
От: Rob Sargent
Дата:
Сообщение: Re: Pl/pgsql function