Search Postgresql Archives

Converting an hstore into a key/value record

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux