From Bas van Dijk:
To understand these things I would recommend using nix-repl:
$ nix-repl Welcome to Nix version 1.11.2. Type :? for help.
| -- http GET "localhost:3000/items?select=id,name,c1,c2,c3,c4,subitems{id,name}&id=lte.100" | |
| \set rid random(1, 999900) | |
| BEGIN ISOLATION LEVEL READ COMMITTED READ ONLY; | |
| WITH pg_source AS ( | |
| SELECT | |
| "new_m2m_child_queries"."items"."id", | |
| "new_m2m_child_queries"."items"."name", |
| -- Usage with nix: | |
| -- nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [ optparse-applicative random ])" --run "runhaskell Main User Minimax" | |
| -- Then input the numbers (1-9) that represent the position of the mark | |
| -- | |
| -- runhaskell Main User Random (first play User) | |
| -- runhaskell Main Minimax User (second play User) | |
| -- Using MiniMax can take a while | |
| -- | |
| module Main where |
| docker run -d -p 5433:5432 pipelinedb/pipelinedb:0.9.9 | |
| PGPASSWORD=pipeline psql -h localhost -p 5433 -U pipeline -d pipeline <<EOF | |
| CREATE STREAM wiki_stream (hour timestamp, project text, title text, view_count bigint, size bigint); | |
| CREATE CONTINUOUS VIEW wiki_stats AS | |
| SELECT hour, project, | |
| count(*) AS total_pages, | |
| sum(view_count) AS total_views, | |
| min(view_count) AS min_views, |
| version: '3' | |
| services: | |
| db: | |
| image: timescale/timescaledb:latest-pg10 | |
| ports: | |
| - "5432:5432" | |
| environment: | |
| POSTGRES_DB: devices_small | |
| POSTGRES_USER: app_user | |
| pgrest: |
| # Minimal example of getting a PostgREST API running from scratch for | |
| # testing purposes. It uses docker to launch a postgres database and | |
| # a postgrest api server. | |
| # This should not be used to deploy a production system but to | |
| # understand how postgrest works. In particular there is no security | |
| # implemented, see the docs for more. | |
| # https://postgrest.org/en/v4.4/ |
| %.hex: %.asm | |
| avra -fI $< | |
| rm *.eep.hex *.obj *.cof | |
| all: $(patsubst %.asm,%.hex,$(wildcard *.asm)) | |
| upload: ${program}.hex | |
| avrdude -c arduino -p m328p -P /dev/arduino-uno -b 115200 -U flash:w:$< | |
| monitor: |
| -- child embed, cte better cost, almost half of subselect | |
| -- cost=31864.78..31864.80 | |
| explain WITH pg_source AS ( | |
| SELECT "test"."clients".*, COALESCE((SELECT array_to_json(array_agg(row_to_json("projects".*))) FROM (SELECT "test"."projects"."name" FROM "test"."projects" WHERE "test"."projects"."client_id" = "test"."clients"."id" ) "projects"), '[]') AS "projects" FROM "test"."clients" | |
| ) SELECT null AS total_result_set, | |
| pg_catalog.count(_postgrest_t) AS page_total, | |
| array[]::text[] AS header, | |
| coalesce(array_to_json(array_agg(row_to_json(_postgrest_t))), '[]')::character varying AS body | |
| FROM ( SELECT * FROM pg_source) _postgrest_t; |
| select current_setting('response.smth', true) is null; -- gives true | |
| begin; | |
| set local "response.smth" = 'value'; | |
| commit; -- or rollback | |
| select current_setting('response.smth', true) is null; -- gives false since current_setting('response.smth') now is equal to '' |