Skip to content

Latest commit

 

History

History
45 lines (35 loc) · 1.27 KB

README.md

File metadata and controls

45 lines (35 loc) · 1.27 KB

PostgreSQL-DataSketches

PostgreSQL-DataSketches brings DataSketches functions to PostgreSQL via PostgreSQL Adaptor for C++ DataSketches.

Run in Docker

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d study/postgresql-datasketches

Test DataSketches functions in Docker

Example

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d study/postgresql-datasketches

docker exec -it some-postgres psql -U postgres

postgres=# SELECT cpc_sketch_get_estimate(cpc_sketch_union(respondents_sketch)) AS num_respondents, flavor
FROM (
  SELECT
    cpc_sketch_build(respondent) AS respondents_sketch,
    flavor,
    country
  FROM (
    SELECT * FROM (
      VALUES (1, 'Vanilla', 'CH'),
             (1, 'Chocolate', 'CH'),
             (2, 'Chocolate', 'US'),
             (2, 'Strawberry', 'US')) AS t(respondent, flavor, country)) as foo
  GROUP BY flavor, country) as bar
GROUP BY flavor;

Result

 num_respondents |   flavor   
-----------------+------------
               1 | Strawberry
               1 | Vanilla
2.00016277723359 | Chocolate
(3 rows)