This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
house : [{ | |
id: 1, | |
name: test', | |
rooms: [{ | |
id:'a', | |
name: 'room a', | |
entities: [{ | |
id: 'x', | |
name: 'No more examples', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
combineReducers({ | |
house: wrapReducerProperties( | |
rooms: wrapReducerProperties({ | |
entities: wrapReducerProperties({ | |
foo:fooReducer, | |
test:testReducer | |
}, | |
entitiesReducer) | |
), | |
houseReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create the master table tablename_with_partition: | |
-- You should use the same exact schema as the one from the non partitioned table. | |
CREATE TABLE tablename_with_partition | |
( | |
id integer NOT NULL DEFAULT nextval('tablename'::regclass), | |
"name" character varying(150) NOT NULL, | |
description text NOT NULL, | |
period character varying(10) NOT NULL | |
CONSTRAINT tablename_with_partition_pkey PRIMARY KEY (id) | |
) WITH ( OIDS=FALSE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Attach a magic function to the insert of this table: | |
CREATE OR REPLACE FUNCTION create_partition_and_insert() | |
RETURNS TRIGGER AS | |
$BODY$ | |
DECLARE | |
partition VARCHAR(25); | |
BEGIN | |
partition := TG_RELNAME || '_' || NEW.period || ‘p’; | |
IF NOT EXISTS(SELECT relname | |
FROM pg_class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TRIGGER tablename_insert_trigger | |
BEFORE INSERT ON tablename_wtih_partition | |
FOR EACH ROW EXECUTE PROCEDURE create_partition_and_insert(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copy data from the non partitioned to the partitioned version: | |
INSERT INTO tablename_with_partition SELECT * tablename; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION run_on_partitions(TEXT, TEXT) | |
RETURNS INTEGER AS $$ DECLARE partition RECORD; | |
tablename TEXT = $1; | |
sql TEXT = $2; | |
sqlReplaced TEXT; | |
BEGIN tablename := tablename || '%p'; | |
FOR partition IN SELECT relname :: TEXT AS rel | |
FROM pg_class | |
WHERE relname :: TEXT LIKE tablename AND relkind = 't' | |
ORDER BY relname LOOP sqlReplaced := replace(sql, '', partition.rel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 - SELECT | |
1 - [ FROM ... ] | |
2 - [ WHERE ... ] | |
3 - [ GROUP BY ... ] | |
4 - [ HAVING ... ] | |
5 - WINDOW window_name AS ( | |
[ PARTITION BY ... ] | |
[ ORDER BY ... ] | |
[ RANGE ... ] | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
*, | |
min(salary) | |
OVER report_by_category, | |
avg(salary) | |
OVER report_by_category, | |
max(salary) | |
OVER report_by_category | |
FROM employe | |
WINDOW report_by_category AS ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id | name | salary | category | min | avg | max | |
-----+-------------------+--------+----------+------+------------------+------ | |
1003 | Employe name 1003 | 6515 | C | 1009 | 5550.74427480916 | 9996 | |
1005 | Employe name 1005 | 8187 | C | 1009 | 5550.74427480916 | 9996 | |
1001 | Employe name 1001 | 6106 | D | 1001 | 5507.41912512716 | 9976 | |
1002 | Employe name 1002 | 2491 | E | 1001 | 5551.63221884498 | 9997 | |
1004 | Employe name 1004 | 5130 | E | 1001 | 5551.63221884498 | 9997 |
OlderNewer