_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

PostgreSQL Advanced Features

10. 07. 2024 1 min read intermediate

PostgreSQL je nejpokročilejší open-source databáze. JSONB, window functions, partitioning — features, které v MySQL nenajdete.

JSONB

– Uložení a dotazování CREATE TABLE events (id SERIAL, data JSONB); INSERT INTO events (data) VALUES (‘{“type”: “click”, “page”: “/home”}’); SELECT data->>’type’ as event_type FROM events; SELECT * FROM events WHERE data @> ‘{“type”: “click”}’; CREATE INDEX idx_events_data ON events USING GIN(data);

Window Functions

– Ranking SELECT name, department, salary, RANK() OVER (PARTITION BY department ORDER BY salary DESC) as rank, AVG(salary) OVER (PARTITION BY department) as dept_avg FROM employees; – Running total SELECT date, amount, SUM(amount) OVER (ORDER BY date) as running_total FROM transactions;

CTE (Common Table Expression)

WITH monthly_stats AS ( SELECT DATE_TRUNC(‘month’, created_at) as month, COUNT(*) as total, SUM(amount) as revenue FROM orders GROUP BY 1 ) SELECT month, total, revenue, LAG(revenue) OVER (ORDER BY month) as prev_revenue FROM monthly_stats;

Key Takeaway

PostgreSQL JSONB nahradí MongoDB pro většinu use cases. Window functions pro analytiku. CTE pro čitelnost.

postgresqlsqldatabase
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.