Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fair Coffee, Fair Data: Practical Bias Detectio...

Fair Coffee, Fair Data: Practical Bias Detection in Coffee Supply Chains with PostgreSQL

PostgreSQL is evolving beyond its traditional relational roots by adopting property graph query capabilities through SQL/PGQ. This extension enables graph-style pattern matching and traversal directly within PostgreSQL, removing the need for separate graph database systems. For database practitioners, this opens the door to analyzing complex relationships while continuing to rely on PostgreSQL’s mature relational storage, indexing, and performance features.

This session presents a hands-on case study of applying SQL/PGQ to real-world coffee trade data. The coffee supply chain represents a rich and complex graph of farmers, cooperatives, exporters, and markets, where structural bias and unequal opportunities often emerge. By modeling these entities and their relationships as property graphs, we can detect imbalances such as limited market access for smallholder farmers, regional disparities in pricing, and inequities between certified and non-certified producers. Importantly, this type of structural bias analysis is conceptually related to ML bias, where hidden patterns can lead to unfair or unintended outcomes—here applied at the level of trade networks rather than model predictions.

The talk will walk through the full process:
- Designing graph schemas from relational tables
- Building property graphs within PostgreSQL
- Writing SQL/PGQ queries to uncover bias and unfair patterns
- Combining relational and graph queries for deeper insights
- Interpreting and visualizing results in a reproducible workflow

Attendees will gain practical skills in constructing and querying property graphs in PostgreSQL, see how relational and graph paradigms can complement each other, and learn how to adapt these methods to their own datasets. Beyond coffee, the techniques demonstrated are broadly applicable to supply chains, recommendation systems, fraud detection, and fairness-aware analytics.

This session is designed for engineers, DBAs, and analysts who want to explore PostgreSQL’s upcoming graph capabilities in a tangible, real-world scenario, leaving with reproducible queries and actionable insights.

Avatar for Koji Annoura

Koji Annoura

March 12, 2026

More Decks by Koji Annoura

Other Decks in Programming

Transcript

  1. PGConf India 2026 — Friday, 13 March 2026 — 11:40–12:05

    (India Standard Time) Fair Coffee, Fair Data: Practical Bias Detection in Coffee Supply Chains with PostgreSQL Koji Annoura Neo4j Ninja @kojiannoura [email protected]
  2. Who am I ❖ I live in Fukuoka, Japan ❖

    I’m Koji Annoura. ❖ Neo4j Ninja ❖ I love coffee. ❖ J.C.Q.A. Certi fi ed Associate Instructor in Coffee ❖ Certi fi ed SCAJ Coffee Meister ❖ Certi fi ed UCC Coffee Professional
  3. Today’s Journey ❖ 1. Building PostgreSQL with the SQL/PGQ Patch

    Series ❖ 2. SQL/PGQ in SQL:2023 ❖ 3. Show the demo environment ❖ 4. Analyze a coffee trade network ❖ 5. Compare relational SQL and SQL/PGQ queries
  4. Acknowledgements ❖ Graph databases, SQL/PGQ and PostgreSQL by Ashutosh Bapat

    ❖ Some slides reference this work. Used with permission. ❖ Any errors in this presentation are my own. Source: Ashutosh Bapat, PGDay Mumbai 2026 (referenced).
  5. Build Steps ❖ Update package lists ❖ Install build dependencies

    ❖ Get PostgreSQL source ❖ Find the SQL/PGQ patch series ❖ Apply the patch series ❖ Build and install PostgreSQL
  6. Install build dependencies ❖ Before installing build tools, update the

    package index of the system. ❖ Install ❖ build-essential ❖ git ❖ libreadline-dev ❖ zlib1g-dev ❖ fl ex ❖ bison
  7. Get PostgreSQL source ❖ Latest PostgreSQL ❖ Command ❖ git

    clone https://github.com/postgres/ postgres.git
  8. Find the SQL/PGQ patch series ❖ Download SQL/PGQ patches from

    the pgsql-hackers mailing list. ❖ Look for the patch series with the latest date pre fi x. Source: pgsql-hackers mailing list (SQL/PGQ patch series).
  9. Find the SQL/PGQ patch series (update) ❖ Patch series grew

    from 3 to 5 patches. ❖ V20260311-0001-… ❖ v20260311-0002-… ❖ V20260311-0003-… ❖ v20260311-0004-… ❖ v20260311-0005-… Source: pgsql-hackers mailing list (SQL/PGQ patch series).
  10. Apply SQL/PGQ Patch ❖ v20260306 ❖ patch -p1 < ~/PATH_TO_PATCH/v20260306-0001-WIP-SQL-Property-Graph-Queries-SQL-PGQ.patch

    ❖ patch -p1 < ~/PATH_TO_PATCH/v20260306-0002-Simplify-property-not-found-error-message.patch ❖ patch -p1 < ~/PATH_TO_PATCH/v20260306-0003-Ignore-ecpg-output- fi les-in-git.patch ❖ v20260311 ❖ patch -p1 < ~/PATH_TO_PATCH/v20260311-0001-WIP-SQL-Property-Graph-Queries-SQL-PGQ.patch ❖ patch -p1 < ~/PATH_TO_PATCH/v20260311-0002-Simplify-property-not-found-error-message.patch ❖ patch -p1 < ~/PATH_TO_PATCH/v20260311-0003-Ignore-ecpg-output- fi les-in-git.patch ❖ patch -p1 < ~/PATH_TO_PATCH/v20260311-0004-Error-message-for-all-properties-reference.patch ❖ patch -p1 < ~/PATH_TO_PATCH/v20260311-0005-Support-all-properties-reference-in-COLUMN.patch
  11. SQL/PGQ in SQL:2023 ❖ Property Graph Query ❖ https://www.iso.org/standard/79473.html ❖

    SQL:2023 (ISO/IEC 9075:2023) ❖ Part 16 ❖ General information ❖ Status : Published ❖ Publication date : 2023-06 ❖ Stage : International Standard to be revised [90.92] ❖ Edition : 1 ❖ Number of pages : 269 ❖ Technical Committee : ISO/IEC JTC 1/SC 32 Source: ISO/IEC 9075-16:2023 (SQL/PGQ), ISO
  12. SQL/PGQ and GQL ❖ SQL ❖ relational queries ❖ SQL/PGQ

    ❖ graph queries inside SQL ❖ published 2023-06 ❖ GQL ❖ graph query language ❖ published 2024-04 Source: openCypher Project — “SQL and now GQL”, opencypher.org (used for reference)
  13. SQL/PGQ Status in PostgreSQL ❖ In development ❖ Authors ❖

    Peter Eisentraut ❖ Ashutosh Bapat ❖ Reviewers ❖ Junwang Zhao ❖ Henson Choi ❖ Hopefully released in ❖ PostgreSQL 19 (tentative) Reference: Ashutosh Bapat, “Graph databases, SQL/PGQ and PostgreSQL”, PGDay Mumbai 2026
  14. Demo Environment ❖ Host ❖ Apple Silicon ❖ VirtualBox 7.2.6

    ❖ Vagrant 2.4.9 ❖ Box ❖ bento/debian-12 202510.26.0 ❖ generic/debian12 4.3.12 not available for Apple Silicon ❖ Guest Environment ❖ Debian GNU/Linux 12 (bookworm) ❖ PostgreSQL 19devel Screenshot: HashiCorp Vagrant Cloud — bento/debian-12 (hashicorp.com)
  15. Coffee Trade ❖ Coffee is one of the most traded

    products in the world. ❖ More than 25 million farmers grow coffee. Most of them are small family farms. ❖ Coffee is not only a drink. It is also a source of income for many people. Image: Generated with ChatGPT (OpenAI)
  16. Asia ❖ Asia is an important coffee region. ❖ Countries

    like Vietnam, Indonesia, and India produce large amounts of coffee. ❖ Many farmers in Asia depend on the global coffee market. Image: Generated with ChatGPT (OpenAI)
  17. Supply Chain Model ❖ Coffee moves through several steps before

    reaching the fi nal consumer. ❖ Farmers → Cooperatives → Exporters → Roasters ❖ Roasters then supply coffee to shops, companies, and consumers. Image: Generated with ChatGPT (OpenAI)
  18. Find the SQL/PGQ patch series (update) ❖ From 3 to

    5 patches ❖ V20260311-0001-… ❖ v20260311-0002-… ❖ V20260311-0003-… ❖ v20260311-0004-… ❖ v20260311-0005-… Source: pgsql-hackers mailing list (SQL/PGQ patch series).
  19. Questions ❖ Which exporters dominate the network? ❖ Which cooperatives

    depend on one buyer? ❖ Which farmers reach global markets? ❖ Which farmers connect to Bangalore Coffee Lab
  20. Path Queries ❖ Many interesting questions involve paths ❖ Example

    ❖ Farmer → Cooperative → Exporter → Roaster Image: Generated with ChatGPT (OpenAI)
  21. SQL Complexity ❖ As relationships grow ❖ JOIN JOIN JOIN

    JOIN JOIN ❖ Queries become harder to read.
  22. Graph Perspective ❖ Nodes ❖ Farmer ❖ Cooperative ❖ Exporter

    ❖ Roaster ❖ Edges ❖ member_of ❖ sold_to_exporter ❖ sold_to_roaster
  23. 2-Hop: Analysis ❖ Farmer → Cooperative → Exporter ❖ Which

    exporters receive coffee from the most cooperatives?
  24. 3-Hop: Analysis ❖ Farmer → Cooperative → Exporter → Roaster

    ❖ Which roasters receive coffee from speci fi c regions
  25. More Relational Patterns ❖ So far we analyzed 1-hop, 2-hop,

    and 3-hop patterns. ❖ But real supply chains are more complex. ❖ Some relationships bypass intermediate nodes: ❖ Cooperative → Roaster ❖ Farmer → Exporter ❖ Farmer → Roaster
  26. Key Insight ❖ SQL answers ❖ How much? ❖ Graph

    answers ❖ How is it connected? ❖ Together they reveal hidden structures in complex systems.
  27. Open Data ❖ Many organizations publish coffee trade data. ❖

    Examples include the International Coffee Organization and FAOSTAT. ❖ Open data makes this analysis reproducible. Image: Generated with ChatGPT (OpenAI)
  28. Structural Bias ❖ However, the trade network is not always

    balanced. ❖ Some exporters control many trade connections. ❖ Many farmers depend on only a few buyers. Image: Generated with ChatGPT (OpenAI)
  29. Structural Bias ❖ Colors ❖ Exporter (Orange) ❖ Farmer (Pink)

    ❖ Market (Blue) ❖ Some exporters connect to many roasters. ❖ Others connect to only one. ❖ This creates structural bias in the network.
  30. Key Takeaways ❖ Coffee trade networks are graphs. ❖ SQL

    can query them, but SQL/PGQ expresses the structure more naturally. ❖ Graph queries help reveal hidden patterns in real data.
  31. Thank You / Q&A ❖ Thanks for listening! ❖ Queries

    re fl ect the structure we design. So relationships matter. ❖ 📧 [email protected] 🐦 @kojiannoura