Skip to content

A little toolkit for multiset (bag) basic operations, storing bags into JSON objects

Notifications You must be signed in to change notification settings

datasets-br/sql-json-bags

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sql-json-bags

A little toolkit for multiset (bag) basic operations, storing bags into JSONb objects.

Two flavors: schema lib implementation and direct implementation (schema public).

As schema bag library

As a restric jsonb-schema, with only key-value pairs and value as integer, the datatype is named jbags.

  • bag.valid(JSONb) ret boolean:
    Validate internal representation as bag (key-multiplicity pairs).
  • bag.sc(JSONb) ret bigint:
    Scalar cardinality of the bag.
  • bag.contains(JSONb, text) ret boolean:
    Checks whether the element is present (at least once) in the bag.
  • bag.j_as_t(JSONb[]) ret SETOF bag.ref:
    Returns an array of JSONb-bag representations as an element-multiplicity table.
  • bag.j_as_t(JSONb) ret SETOF bag.ref:
    Similar.
  • bag.scaled_by(JSONb,int) ret JSONb:
    Scalar multiplication. $2⊗$1.
  • bag.intersection(JSONb[]) ret JSONb:
    ...
  • bag.union(JSONb[]) ret JSONb:
    ...
  • bag.sum(JSONb[]) ret JSONb:
    ...
  • bag.is_sub(JSONb, JSONb[]) ret boolean:
    Checks $1 ⊑ ($2[1] ∩ $2[2] ∩...), that is if $1=($1 ∩ $2[1] ∩ $2[2] ∩...).
  • bag.intersection(JSONb,JSONb) ret JSONb:
    $1 ∩ $2.
  • bag.is_sub(JSONb, JSONb) ret boolean:
    Checks $1 ⊑ $2, whether each element in the bag1 occurs in bag1 no more often than it occurs in the bag2.
  • bag.union(JSONb,JSONb,boolean DEFAULT true) ret JSONb:
    ... Trying to optimize the union (or sum) of two bags.
  • bag.j_as_t(JSONb) ret SETOF bag.ref:

See bag_as_schema.sql source code.

As public library

Same as bag.*() but in the public catalog of functions with jbag datatype as parameter.
NOTE: j_as_t() renamed to astable().

See bag.sql source code.

About

A little toolkit for multiset (bag) basic operations, storing bags into JSON objects

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published