Typed hstore proposal - Mailing list pgsql-hackers

From Johann 'Myrkraverk' Oskarsson
Subject Typed hstore proposal
Date
Msg-id x6ehvx1jd0.fsf@2ndquadrant.com
Whole thread Raw
Responses Re: Typed hstore proposal  (Christopher Browne <cbbrowne@gmail.com>)
Re: Typed hstore proposal  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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
andServices  --+--                                                                 |  Blog:
http://my.opera.com/myrkraverk/blog/


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Page Checksums + Double Writes
Next
From: Christopher Browne
Date:
Subject: Re: Typed hstore proposal