Created
July 1, 2026 06:03
-
-
Save up1/10af01678cd0977a21d2d97c941d2b95 to your computer and use it in GitHub Desktop.
Postgresql 19 beta 1
This file contains hidden or 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 tables for customers, orders, customer_orders, and a property graph to represent the relationships between customers and their orders. | |
| CREATE TABLE customers ( | |
| customer_id INT PRIMARY KEY, | |
| name VARCHAR(100), | |
| email VARCHAR(100) | |
| ); | |
| CREATE TABLE orders ( | |
| order_id INT PRIMARY KEY, | |
| customer_id INT, | |
| order_date DATE, | |
| amount DECIMAL(10, 2), | |
| FOREIGN KEY (customer_id) REFERENCES customers(customer_id) | |
| ); | |
| CREATE TABLE customer_orders ( | |
| customer_id INT, | |
| order_id INT, | |
| PRIMARY KEY (customer_id, order_id), | |
| FOREIGN KEY (customer_id) REFERENCES customers(customer_id), | |
| FOREIGN KEY (order_id) REFERENCES orders(order_id) | |
| ); | |
| -- Insert 5 customers | |
| INSERT INTO customers (customer_id, name, email) VALUES | |
| (1, 'Alice Smith', 'user01@example.com'), | |
| (2, 'Bob Johnson', 'user02@example.com'), | |
| (3, 'Charlie Brown', 'user03@example.com'), | |
| (4, 'David Wilson', 'user04@example.com'), | |
| (5, 'Eve Davis', 'user05@example.com'); | |
| -- Insert 10 orders | |
| INSERT INTO orders (order_id, customer_id, order_date, amount) VALUES | |
| (1, 1, '2026-01-15', 150.00), | |
| (2, 1, '2026-02-20', 200.00), | |
| (3, 2, '2026-03-05', 75.00), | |
| (4, 2, '2026-03-15', 125.00), | |
| (5, 3, '2026-04-10', 300.00), | |
| (6, 3, '2026-04-20', 50.00), | |
| (7, 4, '2026-05-01', 400.00), | |
| (8, 4, '2026-05-15', 250.00), | |
| (9, 5, '2026-06-01', 100.00), | |
| (10, 5, '2026-06-10', 175.00); | |
| -- Insert customer_orders relationships | |
| INSERT INTO customer_orders (customer_id, order_id) VALUES | |
| (1, 1), | |
| (1, 2), | |
| (2, 3), | |
| (2, 4), | |
| (3, 5), | |
| (3, 6), | |
| (4, 7), | |
| (4, 8), | |
| (5, 9), | |
| (5, 10); | |
| -- Create a property graph to represent the relationships between customers and their orders | |
| CREATE PROPERTY GRAPH store_graph | |
| VERTEX TABLES ( | |
| customers LABEL customer, | |
| orders LABEL "order" | |
| ) | |
| EDGE TABLES ( | |
| customer_orders | |
| SOURCE customers | |
| DESTINATION orders | |
| LABEL placed_order | |
| ); | |
| -- Customers active in 3 months | |
| SELECT customer_name | |
| FROM GRAPH_TABLE (store_graph MATCH (c IS customers)-[IS customer_orders]->(o IS orders | |
| WHERE o.order_date > DATE_TRUNC('month', CURRENT_DATE) - INTERVAL '3 month') COLUMNS (c.name AS customer_name)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment