Convert Domain Calculus into (Postgre-)SQL

45 views Asked by At

Let there be a table Person with attributes (columns) Name and Age.

Given the following expression in Domain Calculus:
{[name] | ∃ age (Person(name,age) ∧ age≥18)}

I want to create the corresponding SQL query.

Is it possible (not asking if it is good practice) to create such an SQL query (not only in this specific case) WITHOUT knowing the database schema? So I do not need to know that the table Person has the columns named Name and Age.

I have thought about accessing the table through column indices, but I am confused.

1

There are 1 answers

0
CodingTil On BEST ANSWER

Thanks to @philipxy I have stumbled upon this answer:

WITH p(name,age) AS (SELECT * FROM PERSON)
SELECT name FROM p WHERE age>=18