CPrefSQL             Obter código-fonte do CPrefMiner  Executar versão experimental (Web)  Time de desenvolvimento  Publicações relacionadas

What is CPref-SQL?

(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.

How to express preferences and execute a CPref-SQL query?

The user can express your own preferences by means of conditional rules. The command CREATE PREFERENCES is responsible for this creation:

CREATE PREFERENCES <preference_name>

FROM <relations_list>

AS <cp-rules_list> ;

Once expressed the preferences, a CPref-SQL query is done by using the ACCORDING TO PREFERENCES clause.

SELECT <attribute_list>

FROM <relations_list>

WHERE <where_conditions>


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.

A Running Example

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:


FROM movies

AS  years=90 > years=80 [1,4,5] AND

IF director='Woody Allen' THEN actor='Charlotte Rampling' > actor='Mia Farrow' [1] AND 

IF genre='comedy' and years=80 THEN director='Joel Coen' > director='Woody Allen' [1,5] AND

IF years=80 THEN genre='drama' > genre='comedy' [1] ;

SELECT title

FROM movies

WHERE genre <> 'romance'


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

Laboratório de Sistemas de Informação
Faculdade de Computação - Universidade Federal de Uberlândia
Av. João Naves de Ávila, 2121 − Campus Santa Mônica - Bloco 5K
CEP: 38.400-902 - Uberlândia - Minas Gerais - Brasil
Fone: 55 (34) 3239-4568