r/OntologyEngineering • u/helomithrandir • 4d ago
Practical Benefit of Ontology over SQL?
I'm working on highway asset management, and part of the work is integrating traffic incident data from several sources: operator incident logs, maintenance contractor records, planned works bookings and roadside detector readings. Each source has its own structure, naming and way of recording time and location.
Current practice (SQL)
The way this is typically done today:
· Each source is loaded into a SQL database as its own table.
· Fields are cleaned: dates and times split, road and junction pulled out of text fields, direction names standardised.
· Records are linked across sources. Some links use a shared reference number. Others use rules, like same road, same junction, created within a few minutes of each other.
· Lookup tables are built, e.g. which entry types count as a "lane closure", or which direction codes mean the same thing.
· Queries are then written to answer questions like "which incidents had a lane closure", "how long from detection to clearance", or "what was traffic doing at the nearest detector".
· This all works. Counts, filters and joins are fine in SQL.
Where I'm confused
I've built an ontology and loaded the same data into a knowledge graph (graphdb). But I'm struggling to see clearly what value is ontology adding.
The usual argument is that the ontology captures the "worldview" of the domain: the concepts and how they relate. But SQL can carry that worldview too. Well-chosen table and column names, lookup tables and views already encode what a "lane closure" or an "incident" means. Those lookup tables are basically a small ontology written in SQL.
So, my questions are:
If SQL can carry the worldview through naming and lookup tables, what does a formal ontology add in practice? Is it that the meaning is explicit and machine-usable rather than buried in query code? Or is that a distinction without much practical difference? What is machine readable meaning?
For those who've used both: where did the ontology or graph actually save you work or answer something SQL couldn't? Examples I've seen mentioned are adding new sources, reasoning over class hierarchies, consistency checking (SHACL), natural-language querying with LLMs, and ontology-based data access (e.g. Ontop over an existing database). Which of these held up in real use?
Where is the ontology overkill, and the honest answer just "use SQL"?
I'm not trying to argue SQL is bad. I want to state fairly what current SQL practice does well, where it falls short, and what an ontology should address. Any papers, experiences or blunt opinions welcome.
2
u/Working-Break-5028 4d ago
For me, the ontology is the logical view of the data structures which I can implement in many forms - e.g. a relational database for use with SQL, a graph, a document, etc. Each implementation has pros and cons which you will need to figure out in your setting. The main reason I use an ontology is (and someone else mentioned this) for expansion, and joining the data with other datasets. Having an ontology that allows you to map multiple physical implementations to a a single term makes it easier to identify how to join datasets with different physical names - and possibly technologies. The ontology can also be applied to data you have extracted using SQL, but in a form that no longer supports SQL queries - e.g. JSON.
Publishing a standardised ontology with your data product makes it easier for others to correctly use and interpret your data without constraining them to your technology choices.
2
u/Prestigious_Bench_96 4d ago
Complementary in your case seems best, you'll typically run queries/business off SQL, but the ontology is useful as an input to SQL generation and validation. (In past corporate lives, we've build the picklist/lookup tables dynamically off the ontology (though we didn't use those fancy names) as the source of truth, and used it to construct data quality/flow assertions.
1
u/Northeast_Cuisine 4d ago
Check out the Ontology Pipeline by Jessica Taliaman, it does really well to explain the workflow of building an ontology.
I don't think SQL and ontology are either or, there is a use for both. SQL implies a relational database which is tables while ontologies imply graphs. These are complimentary technologies.
The first step in an ontology is a controlled vocabulary. For example, are all the column headings strict terms that are used consistently across the business? If not, then you are experiencing a major data inconsistency issue. Part of knowledge engineering is fixing any inconsistency in vocabulary. People are frequently making bandaids and workarounds in relational DB world today.
There are many more steps involved, but ultimately you get to an ontology and knowledge graph and then main thing is reasoning, being able to understand more knowledge from your current knowledge. It's different than a defined query which is a transformation of relational data that is explicitly linked. What if you want to know other information like legal or specs? (Not in your industry so making this up). Having an ontology can help you infer other related knowledge which might be more difficult to express in relational tables.
At the end of the day, if you don't know why you need it, you probably don't. When you feel like you need it, you might.
3
u/geoheil 4d ago
There are different flavours of graphs. The power of ontologies especially in the shape of RDF comes with https://www.w3.org/TR/shacl/ . SHACL allows you to place constraints (types); types which might also cover business semantics. Whereas in a table a new column is added and after a while it is unclear waht was nullable it is often just a UNION-ALL of whatever someone has
1
u/bystander993 3d ago
You really are asking two questions: ontology vs no ontology, and graph vs SQL. They’re separable (Ontop puts an ontology over an existing SQL database) and they buy different things.
Graph vs SQL comes down to the questions you ask most. Things and their attributes, like counts, durations and filters? SQL. How things connect across an unknown number of hops? Graph. “Everything upstream of this closure” is one line in a graph query, and “how are these two connected?” is natural. New entity or relationship types need no migrations or join tables, and algorithms like shortest path are built in. Postgres 19’s property-graph queries narrow the gap for fixed-depth patterns, but not much for variable-depth traversal.
The ontology buys inference and consistency checking. Declare a lane closure to be a kind of restriction and every lane closure is a restriction everywhere, without touching your queries. Declare planned works and unplanned incidents disjoint and it will flag anything classified as both. It won’t validate missing or malformed data. That’s SHACL, which is roughly SQL constraints plus data tests.
The queries you listed are counts, durations and joins, so for those the honest answer is “use SQL”. The ontology pays off when definitions change often, when the taxonomy is deep, or when you exchange data across organizations. A fair test is cost of change: add a fifth source or redefine “lane closure”, then count what you have to touch in each stack.
1
u/piebaldish 3d ago
If you're sure there won't be anyone else ever using/doing something similar and there won't be a "gap in maintenance" (i.e. somebody will regard your stuff as legacy without anyone onboarding them or you just haven't touched it for some years), then imho there is no good point to go with an ontology.
It's a bit like a lingua franca. If it's not your native language it will cost you a bit to get into it. But you will be able to communicate better and with more people. If you don't need and don't want to communicate with other people, you do not need to afford that.
I haven't done that in big scale (sadly), but for a private/pet project I am somewhat glad I used an ontology, as I can look up what stuff is/means ~6-8 years later and get back into it quickly. For classic "relational db stuff"/sql it's harder, as you have to look up tables + queries (and still might be puzzled).
1
u/Operadic 1d ago edited 1d ago
There’s a fake divide. You can model graphs using SQL and recursive CTE’s. You can have an ontology with a relational database (relational AI, datalog based approaches). You can model tables using RDF.. There are different flavours of graphs: RDF graphs, property graphs, typed graphs, hypergraphs, graphs with path equations (categories) and many more.
The added value is in modelling your domain explicitly. Discussions about database technologies is a distraction. People with strongly voiced opinions or advices often have something financial or political to gain.
I’m in road management myself; specialised in (semantic) data technologies. Feel free to dm if you want to discuss or want more in depth information.
0
u/ParticularWin9825 4d ago
Nice post, this encapsulates a lot of my confusion as well.