Skip site navigation (1) Skip section navigation (2)

Typed hstore proposal

From: "Johann 'Myrkraverk' Oskarsson" <johann(at)2ndquadrant(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Typed hstore proposal
Date: 2011-12-22 01:32:43
Message-ID: x6ehvx1jd0.fsf@2ndquadrant.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Hi all,

I mean to create a typed hstore, called tstore for now.  I'm open to
name suggestions.  It'll only support a subset of core Postgres types
to begin with.  Keys are always text, it's the value that's typed.

Usage is very similar to hstore; this is not a complete reference.

  tstore( text, text)   Creates a text key-value pair.

  tstore( text, int4 )  Creates an integer key-value pair.

  tstore -> text        Returns a tvalue, which is basically an
                        oid-value pair.

  typeof( tvalue )      Returns the oid.

  tvalue::int4          The integer value.

  tvalue::text          The text value.

  each_int( tstore )    Set of all keys and values where the value
                        is int4.

  each_text( tstore )   Set of all keys and values where the value
                        is text.

  each( tstore )        Set of all keys and values as tvalues.

Some examples:

# select 'text: "a"'::tvalue;
  tvalue
----------
 text: "a"
(1 row)

# select 'integer: 17'::tvalue;
  tvalue
----------
 int4: 17
(1 row)

# select each_int( '"a" -> text: "b", "b" -> int: 17'::tstore );
 ?column? | ?column?
----------+----------
 "b"      |       17
(1 row)

#select '"a" -> text: "b", "b" -> int: 17'::tstore -> 'a'; 
  ?column? 
-----------
 text: "a"
(1 row)


All comments are welcome.  As the project matures, I'm sure other
needed functions will crop up.


-- 
   Johann Oskarsson                http://www.2ndquadrant.com/    |[]
   PostgreSQL Development, 24x7 Support, Training and Services  --+--
                                                                  |
   Blog: http://my.opera.com/myrkraverk/blog/

Responses

pgsql-hackers by date

Next:From: Christopher BrowneDate: 2011-12-22 03:40:02
Subject: Re: Typed hstore proposal
Previous:From: Robert HaasDate: 2011-12-22 00:45:19
Subject: Re: Page Checksums + Double Writes

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group