SlideShare a Scribd company logo
1 of 30
Download to read offline
PostgreSQL для хипстеров
или почему ваш следующий проект должен быть на PostgreSQL
https://goo.gl/1uAZNi
Кто использует PostgreSQL
• по привычке
• по предложению заказчика
• на хайпе
Как мы выбираем БД?
• по привычке
• по предложению заказчика
• на хайпе
• Исходя из требований
Как мы выбираем БД?
• 2003 — PG 8.2 - HSTORE
• 2012 — PG 9.2 - JSON
• 2013 — nested HSTORE (proposal) и
JSONB
• 2014 —PG 9.4 - JSONB, forget nested
hstore
• 2018? — SQL/JSON for 10.X or 11
JSON(B) в PostgreSQL
• select * from table where js->’field’ = 'foo' // field match
• where js @> '{"foo": "bar"}' // key-value match top-level
• where js ? 'b'// key exist
• {"a": 1} || {"b": 2} // {a: "1", b: "2"} - concat
• {a: "1", b: "2"} - "a" // {b: "2"} - delete key
JSON(B) в PostgreSQL
Найти "что-нибудь" красное
Table "public.js_test"
Column | Type | Modifiers
--------+---------+-----------
id | integer | not null
value | jsonb |
select * from js_test;
id |
----+-----------------------------------------------------------------------
1 | [1, "a", true, {"b": "c", "f": false}]
2 | {"a": "blue", "t": [{"color": "red", "width": 100}]}
3 | [{"color": "red", "width": 100}]
4 | {"color": "red", "width": 100}
5 | {"a": "blue", "t": [{"color": "red", "width": 100}], "color": "red"}
6 | {"a": "blue", "t": [{"color": "blue", "width": 100}], "color": "red"}
7 | {"a": "blue", "t": [{"color": "blue", "width": 100}], "colr": "red"}
8 | {"a": "blue", "t": [{"color": "green", "width": 100}]}
9 | {"color": "green", "value": "red", "width": 100}
(9 rows)
WITH RECURSIVE t(id, value) AS (
SELECT * FROM js_test
UNION ALL (
SELECT
t.id,

COALESCE(kv.value, e.value) AS value
FROM t
LEFT JOIN LATERAL jsonb_each(
CASE WHEN jsonb_typeof(t.value) ='object'
THEN t.value ELSE NULL END
) kv ON true
LEFT JOIN LATERAL jsonb_array_elements(
CASE WHEN jsonb_typeof(t.value) = 'array'
THEN t.value ELSE NULL END

) e ON true
WHERE
kv.value IS NOT NULL
OR e.value IS NOT NULL
)
)
SELECT js_test.* FROM (
SELECT id FROM t
WHERE
value @> '{"color":"red"}'
GROUP BY id

) x
JOIN js_test ON js_test.id = x.id;
Найти "что-нибудь" красное
Want some SQL?
SELECT * FROM js_test
WHERE
value @@ '*.color = "red"';
JSQuery
https://github.com/postgrespro/jsquery
• Новый тип данных jsonpath
• Функции для конструирования JSON
• Функции для выполнения запросов к JSON-полям
SQL / JSON (SQL-2016)
SELECT * FROM js_test 

WHERE 

JSON_EXISTS(value, '$.**.color ? (@ == "red")');
JSON - агрегация
JSON-агрегация
SELECT * FROM users 

LEFT JOIN comments ON comments.user_id = users.id
users.id users.name comments.id comments.text comments.user_id comments.created_at
1 alice 1 hello 1 31.12.2017 23:59:50
1 alice 2 Happy NY! 1 01.01.2018 00:00:10
2 bob 3 You too! 2 01.01.2018 00:00:50
JSON-агрегация
select 

users.*, json_agg(comments.*) as comments

from users
left join comments on comments.user_id = users.id
group by users.id
users.id users.name comments
1 alice [

{ id: 1, text: "hello", created_at: "31.12.2017 23:59:50" }, 

{ id: 2, text: "Happy NY!", created_at: "01.01.2018 00:00:10"}

]
2 bob [{ id: 3, text: "You too!", created_at: "01.01.2018 00:00:50"}]
JSON-агрегация
select 

users.*, json_agg(comments.* ORDER BY created_at DESC) as comments

from users
left join comments on comments.user_id = users.id
group by users.id
users.id users.name comments
1 alice [

{ id: 1, text: "hello", created_at: "31.12.2017 23:59:50" }, 

{ id: 2, text: "Happy NY!", created_at: "01.01.2018 00:00:10"}

]
2 bob [{ id: 3, text: "You too!", created_at: "01.01.2018 00:00:50"}]
Оконные функции
select * from events
id type source_id created_at
1 foo 1
2 bar 2
3 a 1
4 b 2
5 c 3
6 d 1
7 e 1
Последние два события по каждому source_id?
Оконные функции
SELECT ROW_NUMBER() OVER (PARTITION by source_id) as row_number, * from events
row_number id type source_id created_at
1 7 e 1
2 6 d 1
3 3 a 1
4 1 foo 1
1 4 b 2
2 2 bar 2
1 5 c 3
Последние два события по каждому source_id?
Оконные функции
WITH events_cte AS (
SELECT
row_number() OVER (PARTITION by source_id) AS row_number, *
FROM events
) SELECT * FROM events_cte WHERE row_number <= 2
row_nunmber id type source_id created_at
1 7 e 1
2 6 d 1
1 4 b 2
2 2 bar 2
1 5 c 3
Оконные функции
• Все агрегирующие функции
• row_number, rank, dense_rank, percent_rank, cum_dist
• ntile(n)
• lag(value), lead(value)
• first_value, last_value, nth_value
• Много процессов
• Много серверов
Advisory locking
Advisory locking
1.Start transaction
2.pg_try_advisory_lock?
3.if success - start_operation()
4.else abort transaction
5.commit transaction -> release lock
1. Start transaction
2. pg_try_advisory_lock?
3. if success - start_operation()
4. else abort transaction
5. commit transaction -> release lock
process 1 process n…
Foreign Data Wrappers
• csv
• json
• mysql / postgres / oracle
• mongo
• elastic
• rest api
• whatever *
Foreign Data Wrappers
• MongoDB 3.2 now powered by PostgreSQL
• https://www.linkedin.com/pulse/mongodb-32-now-powered-
postgresql-john-de-goes/
Last but not least
• materialized view
• full text search
• pl/v8
• listen / notify
• native partitioning
• PostGIS
• where created_at <= NOW() - interval '5 weeks 2 hours 12
minutes'
• RDS / Aurora
node_modules
• MassiveJS - https://github.com/dmfay/massive-js
• MQL - https://github.com/marpple/MQL



const posts = await QUERY `SELECT * FROM posts WHERE id = ${id}`
• Postgraphile - https://www.graphile.org/postgraphile/
Links
• https://postgresweekly.com
• https://dbweekly.com
• https://github.com/dhamaniasad/awesome-postgres
• https://nodeweekly.com
Статистика переходов
Вопросы?
Спасибо!

More Related Content

What's hot

NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
Async Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleAsync Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleVladimir Kostyukov
 
(Rx).NET' way of async programming (.NET summit 2017 Belarus)
(Rx).NET' way of async programming (.NET summit 2017 Belarus)(Rx).NET' way of async programming (.NET summit 2017 Belarus)
(Rx).NET' way of async programming (.NET summit 2017 Belarus)Stas Rivkin
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersRick Beerendonk
 
Rx.NET, from the inside out - Codemotion 2018
Rx.NET, from the inside out - Codemotion 2018Rx.NET, from the inside out - Codemotion 2018
Rx.NET, from the inside out - Codemotion 2018Stas Rivkin
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScriptGarth Gilmour
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architectureJung Kim
 
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip CalçadoJustjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip CalçadoPaulo Silveira
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnMoriyoshi Koizumi
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2Jeado Ko
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...CodeFest
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.jsNoritada Shimizu
 

What's hot (20)

NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
Async Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleAsync Microservices with Twitter's Finagle
Async Microservices with Twitter's Finagle
 
(Rx).NET' way of async programming (.NET summit 2017 Belarus)
(Rx).NET' way of async programming (.NET summit 2017 Belarus)(Rx).NET' way of async programming (.NET summit 2017 Belarus)
(Rx).NET' way of async programming (.NET summit 2017 Belarus)
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
 
Rx.NET, from the inside out - Codemotion 2018
Rx.NET, from the inside out - Codemotion 2018Rx.NET, from the inside out - Codemotion 2018
Rx.NET, from the inside out - Codemotion 2018
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
 
Introduction of ES2015
Introduction of ES2015Introduction of ES2015
Introduction of ES2015
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architecture
 
サイ本 文
サイ本 文サイ本 文
サイ本 文
 
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip CalçadoJustjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
 
C++ programs
C++ programsC++ programs
C++ programs
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
 
MongoDB
MongoDBMongoDB
MongoDB
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
 
Testing (eng)
Testing (eng)Testing (eng)
Testing (eng)
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
 

Similar to NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен быть на PostgreSQL

NoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросовNoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросовCodeFest
 
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...Ontico
 
Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Postgres vs Mongo / Олег Бартунов (Postgres Professional)Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Postgres vs Mongo / Олег Бартунов (Postgres Professional)Ontico
 
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...Ryan B Harvey, CSDP, CSM
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - GuilinJackson Tian
 
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling StrategiesWebscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling StrategiesJonathan Katz
 
Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0Frost
 
PostgreSQLからMongoDBへ
PostgreSQLからMongoDBへPostgreSQLからMongoDBへ
PostgreSQLからMongoDBへBasuke Suzuki
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQLRoberto Franchini
 
C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607Kevin Hazzard
 
Python postgre sql a wonderful wedding
Python postgre sql   a wonderful weddingPython postgre sql   a wonderful wedding
Python postgre sql a wonderful weddingStéphane Wirtel
 
PostgreSQL 9.4 JSON Types and Operators
PostgreSQL 9.4 JSON Types and OperatorsPostgreSQL 9.4 JSON Types and Operators
PostgreSQL 9.4 JSON Types and OperatorsNicholas Kiraly
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
Angular Weekend
Angular WeekendAngular Weekend
Angular WeekendTroy Miles
 
Postgre(No)SQL - A JSON journey
Postgre(No)SQL - A JSON journeyPostgre(No)SQL - A JSON journey
Postgre(No)SQL - A JSON journeyNicola Moretto
 

Similar to NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен быть на PostgreSQL (20)

NoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросовNoSQL для PostgreSQL: Jsquery — язык запросов
NoSQL для PostgreSQL: Jsquery — язык запросов
 
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
 
Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Postgres vs Mongo / Олег Бартунов (Postgres Professional)Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Postgres vs Mongo / Олег Бартунов (Postgres Professional)
 
Oh, that ubiquitous JSON !
Oh, that ubiquitous JSON !Oh, that ubiquitous JSON !
Oh, that ubiquitous JSON !
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling StrategiesWebscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
 
Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0
 
PostgreSQLからMongoDBへ
PostgreSQLからMongoDBへPostgreSQLからMongoDBへ
PostgreSQLからMongoDBへ
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQL
 
Structure on a freeform world
Structure on a freeform worldStructure on a freeform world
Structure on a freeform world
 
C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607
 
Python postgre sql a wonderful wedding
Python postgre sql   a wonderful weddingPython postgre sql   a wonderful wedding
Python postgre sql a wonderful wedding
 
PostgreSQL 9.4 JSON Types and Operators
PostgreSQL 9.4 JSON Types and OperatorsPostgreSQL 9.4 JSON Types and Operators
PostgreSQL 9.4 JSON Types and Operators
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
greenDAO
greenDAOgreenDAO
greenDAO
 
Angular Weekend
Angular WeekendAngular Weekend
Angular Weekend
 
Postgre(No)SQL - A JSON journey
Postgre(No)SQL - A JSON journeyPostgre(No)SQL - A JSON journey
Postgre(No)SQL - A JSON journey
 
Json at work overview and ecosystem-v2.0
Json at work   overview and ecosystem-v2.0Json at work   overview and ecosystem-v2.0
Json at work overview and ecosystem-v2.0
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен быть на PostgreSQL

  • 1. PostgreSQL для хипстеров или почему ваш следующий проект должен быть на PostgreSQL https://goo.gl/1uAZNi
  • 3. • по привычке • по предложению заказчика • на хайпе Как мы выбираем БД?
  • 4. • по привычке • по предложению заказчика • на хайпе • Исходя из требований Как мы выбираем БД?
  • 5.
  • 6. • 2003 — PG 8.2 - HSTORE • 2012 — PG 9.2 - JSON • 2013 — nested HSTORE (proposal) и JSONB • 2014 —PG 9.4 - JSONB, forget nested hstore • 2018? — SQL/JSON for 10.X or 11 JSON(B) в PostgreSQL
  • 7. • select * from table where js->’field’ = 'foo' // field match • where js @> '{"foo": "bar"}' // key-value match top-level • where js ? 'b'// key exist • {"a": 1} || {"b": 2} // {a: "1", b: "2"} - concat • {a: "1", b: "2"} - "a" // {b: "2"} - delete key JSON(B) в PostgreSQL
  • 8. Найти "что-нибудь" красное Table "public.js_test" Column | Type | Modifiers --------+---------+----------- id | integer | not null value | jsonb | select * from js_test; id | ----+----------------------------------------------------------------------- 1 | [1, "a", true, {"b": "c", "f": false}] 2 | {"a": "blue", "t": [{"color": "red", "width": 100}]} 3 | [{"color": "red", "width": 100}] 4 | {"color": "red", "width": 100} 5 | {"a": "blue", "t": [{"color": "red", "width": 100}], "color": "red"} 6 | {"a": "blue", "t": [{"color": "blue", "width": 100}], "color": "red"} 7 | {"a": "blue", "t": [{"color": "blue", "width": 100}], "colr": "red"} 8 | {"a": "blue", "t": [{"color": "green", "width": 100}]} 9 | {"color": "green", "value": "red", "width": 100} (9 rows)
  • 9. WITH RECURSIVE t(id, value) AS ( SELECT * FROM js_test UNION ALL ( SELECT t.id,
 COALESCE(kv.value, e.value) AS value FROM t LEFT JOIN LATERAL jsonb_each( CASE WHEN jsonb_typeof(t.value) ='object' THEN t.value ELSE NULL END ) kv ON true LEFT JOIN LATERAL jsonb_array_elements( CASE WHEN jsonb_typeof(t.value) = 'array' THEN t.value ELSE NULL END
 ) e ON true WHERE kv.value IS NOT NULL OR e.value IS NOT NULL ) ) SELECT js_test.* FROM ( SELECT id FROM t WHERE value @> '{"color":"red"}' GROUP BY id
 ) x JOIN js_test ON js_test.id = x.id; Найти "что-нибудь" красное
  • 11. SELECT * FROM js_test WHERE value @@ '*.color = "red"'; JSQuery https://github.com/postgrespro/jsquery
  • 12. • Новый тип данных jsonpath • Функции для конструирования JSON • Функции для выполнения запросов к JSON-полям SQL / JSON (SQL-2016) SELECT * FROM js_test 
 WHERE 
 JSON_EXISTS(value, '$.**.color ? (@ == "red")');
  • 14.
  • 15. JSON-агрегация SELECT * FROM users 
 LEFT JOIN comments ON comments.user_id = users.id users.id users.name comments.id comments.text comments.user_id comments.created_at 1 alice 1 hello 1 31.12.2017 23:59:50 1 alice 2 Happy NY! 1 01.01.2018 00:00:10 2 bob 3 You too! 2 01.01.2018 00:00:50
  • 16. JSON-агрегация select 
 users.*, json_agg(comments.*) as comments
 from users left join comments on comments.user_id = users.id group by users.id users.id users.name comments 1 alice [
 { id: 1, text: "hello", created_at: "31.12.2017 23:59:50" }, 
 { id: 2, text: "Happy NY!", created_at: "01.01.2018 00:00:10"}
 ] 2 bob [{ id: 3, text: "You too!", created_at: "01.01.2018 00:00:50"}]
  • 17. JSON-агрегация select 
 users.*, json_agg(comments.* ORDER BY created_at DESC) as comments
 from users left join comments on comments.user_id = users.id group by users.id users.id users.name comments 1 alice [
 { id: 1, text: "hello", created_at: "31.12.2017 23:59:50" }, 
 { id: 2, text: "Happy NY!", created_at: "01.01.2018 00:00:10"}
 ] 2 bob [{ id: 3, text: "You too!", created_at: "01.01.2018 00:00:50"}]
  • 18. Оконные функции select * from events id type source_id created_at 1 foo 1 2 bar 2 3 a 1 4 b 2 5 c 3 6 d 1 7 e 1 Последние два события по каждому source_id?
  • 19. Оконные функции SELECT ROW_NUMBER() OVER (PARTITION by source_id) as row_number, * from events row_number id type source_id created_at 1 7 e 1 2 6 d 1 3 3 a 1 4 1 foo 1 1 4 b 2 2 2 bar 2 1 5 c 3 Последние два события по каждому source_id?
  • 20. Оконные функции WITH events_cte AS ( SELECT row_number() OVER (PARTITION by source_id) AS row_number, * FROM events ) SELECT * FROM events_cte WHERE row_number <= 2 row_nunmber id type source_id created_at 1 7 e 1 2 6 d 1 1 4 b 2 2 2 bar 2 1 5 c 3
  • 21. Оконные функции • Все агрегирующие функции • row_number, rank, dense_rank, percent_rank, cum_dist • ntile(n) • lag(value), lead(value) • first_value, last_value, nth_value
  • 22. • Много процессов • Много серверов Advisory locking
  • 23. Advisory locking 1.Start transaction 2.pg_try_advisory_lock? 3.if success - start_operation() 4.else abort transaction 5.commit transaction -> release lock 1. Start transaction 2. pg_try_advisory_lock? 3. if success - start_operation() 4. else abort transaction 5. commit transaction -> release lock process 1 process n…
  • 24. Foreign Data Wrappers • csv • json • mysql / postgres / oracle • mongo • elastic • rest api • whatever *
  • 25. Foreign Data Wrappers • MongoDB 3.2 now powered by PostgreSQL • https://www.linkedin.com/pulse/mongodb-32-now-powered- postgresql-john-de-goes/
  • 26. Last but not least • materialized view • full text search • pl/v8 • listen / notify • native partitioning • PostGIS • where created_at <= NOW() - interval '5 weeks 2 hours 12 minutes' • RDS / Aurora
  • 27. node_modules • MassiveJS - https://github.com/dmfay/massive-js • MQL - https://github.com/marpple/MQL
 
 const posts = await QUERY `SELECT * FROM posts WHERE id = ${id}` • Postgraphile - https://www.graphile.org/postgraphile/
  • 28. Links • https://postgresweekly.com • https://dbweekly.com • https://github.com/dhamaniasad/awesome-postgres • https://nodeweekly.com