(Conditional Preference - SQL) is an extension of SQL with support to conditional preferences. The query language CPref-SQL allows to express conditional preference queries through a qualitative approach.
These queries incorporate the usual hard constraints (declared inside the WHERE clause), as well as soft constraints, specified through a set of preference rules and referenced by the new clause ACCORDING TO PREFERENCES.
The user can express your own preferences by means of conditional rules.
The command CREATE PREFERENCES is responsible for
Once expressed the preferences, a CPref-SQL query is done by using the ACCORDING TO PREFERENCES clause.
Note that one can specify the parameter K, referring to a top-k cp-query. In this case, the query returns the K data tuples which are the most preferred according to the user's preference hierarchy. If the parameter K is not specified, only the most preferred tuples will be returned.
Let us suppose we are given a database relation movies storing information about movies with attributes Title, Genre, Director, Years (decade) and Actor. The following statements express my preferences about movies:
(1) I prefer those movies produced in the 90's rather than those produced in the 80's, if both belongs to the same category (genre);
(2) For Woody Allen's films of the same genre and decade, I prefer those staring the actress Charlotte Rampling than those staring Mia Farrow;
(3) For the comedies produced in the 80's I prefer those directed by Joel Cohen than those directed by Woody Allen;
(4) For the movies produced in the 80's I prefer dramas to comedies.
I would like to list 4 titles of the films which most fulfill my wishes among those stored in the database, but I don't want romances to figure in my list. The corresponding top-k cp-query is:
More details about the semantics of cp-rules and cp-queries can be found in our position paper. In the section demo there is a basic interface that you can create your own preferences and run CPref-SQl queries over the available databases. There is also several examples of queries to help you!
A print screen from pgAdmin