Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.
/ pg-numhstore Public archive

a postgres extension to support inthstore and floathstore types

License

Notifications You must be signed in to change notification settings

adjust/pg-numhstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Overview

This Postgres extension introduces two new data types inthstore and floathstore wich depends on postgres hstore extension. These types are used to hold integer and float values respectively. numhstore comes with certain aggregate and helper functions.

##Operators

inthstore + inthstore

SELECT 'a=>3, b=>2'::inthstore + 'a=>2, c=>5'::inthstore;
           inthstore
------------------------------
 "a"=>"5", "b"=>"2", "c"=>"5"

inthstore - inthstore

SELECT 'a=>3, b=>2'::inthstore - 'a=>2, c=>5'::inthstore;
           inthstore
-------------------------------
 "a"=>"1", "b"=>"2", "c"=>"-5"

inthstore * inthstore

SELECT 'a=>3, b=>2'::inthstore * 'a=>2, c=>5'::inthstore;
            inthstore
--------------------------------
 "a"=>"6", "b"=>NULL, "c"=>NULL

inthstore / inthstore

SELECT 'a=>3, b=>2'::inthstore / 'a=>2, c=>5'::inthstore;
                        floathstore
----------------------------------------------------------
 "a"=>"1.5000000000000000", "c"=>"0.00000000000000000000"

inthstore + int

SELECT 'a=>3, b=>2'::inthstore + 3;
      inthstore
--------------------
 "a"=>"6", "b"=>"5"

inthstore - int

SELECT 'a=>3, b=>2'::inthstore - 3;
      inthstore
---------------------
 "a"=>"0", "b"=>"-1"

inthstore * int

SELECT 'a=>3, b=>2'::inthstore * 3;
      inthstore
--------------------
 "a"=>"9", "b"=>"6"

inthstore / int

SELECT 'a=>3, b=>2'::inthstore / 3;
                           floathstore
--------------------------------------------------------------
 "a"=>"1.00000000000000000000", "b"=>"0.66666666666666666667"

##Functions

array_count

SELECT array_count(ARRAY['a','a','b']);
     inthstore
----------------------
 "a"=>"2", "b"=>"1"

hstore_sum_up

SELECT hstore_sum_up('foo=>10, bar => 15'::inthstore);
 bigint
---------
      25
SELECT hstore_sum_up('foo=>2.5, bar => 4.5'::floathstore);
  numeric
----------
      7.0

array_add

SELECT array_add(Array['foo','foo','bar'], Array[2,3,5]);
       inthstore
------------------------
 "bar"=>"5", "foo"=>"5"

Aggregations

###SUM

SELECT SUM(store) FROM (VALUES('a=>2, b=>4'),('a=>4, b=>6, c=>6'::inthstore) )t(store);
              inthstore
-------------------------------
 "a"=>"6", "b"=>"10", "c"=>"6"

###AVG

SELECT AVG(store) FROM (VALUES('a=>2, b=>4'),('a=>4, b=>6, c=>6'::inthstore) )t(store);
                                       floathstore
---------------------------------------------------------------------------------
 "a"=>"3.0000000000000000", "b"=>"5.0000000000000000", "c"=>"6.0000000000000000"
(1 row)

About

a postgres extension to support inthstore and floathstore types

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages