Skip to content

datasets-br/sql-json-bags

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
January 31, 2018 16:46
February 2, 2018 04:46

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