How to express “no information” in relational algebra?

吃可爱长大的小学妹 提交于 2020-05-28 11:42:48

问题


A task that I'm working on to learn relational algebra is asking me to find the clients who want to rent a property for free, or have not given information about how much they are willing to pay. the table looks like this:

Client(clientNo, firstName, lastName, maxRent)

I have some trouble finding any information about how to represent a lack of information, or an empty data point.. so far I've come up with this where half of the expression is psuedo code:

σ maxRent = 0 OR [no info given] (Client)


回答1:


What rows go in this table? How can we answer without knowing that? How can anyone query without knowing that?

Suppose your table holds the rows where "client [clientid] named [firstname] [lastname] is willing to pay [maxrent]". If a particular client doesn't have both a first & last name then there is no row for them in this table. You can't answer your query with it. If they do have first & last names but you don't know them then you can't set the table--you can't proceed--this table is not for you. Let's further suppose we have all client names. But we similarly can't proceed if we don't know what they are willing to pay.

Suppose your table holds the rows where "clent [clientid] named [firstname] [lastname] has said they are willing to pay [maxrent]". Then you can use it for clients who have given maximum rent. But it can't record anything for other clients. However if you also had a table holding the rows for "client [clientid] named [firstname] [lastname] has not said what they are willing to pay" then you could record for all clients. So you could answer your query.

Suppose your table holds the rows where "cilent [clientid] named [firstname] [lastname] has either said they are willing to pay [maxrent] or has not said how much they are willing to pay and [maxrent]='xxx'". If you have a client's id & names but they haven't said what they are willing to pay then there is a row for them with maxrent='xxx'. Then you can write your query--your "[no info given]" means maxrent='xxx'.

Suppose instead of that table we have two tables, "client [clientid] is named [firstname] [lastname]" & "client [clientid] is willing to pay [maxrent]". Then your table under its meaning is a certain query of those new tables under their meanings. And each of the new tables can be expressed in terms of the old. There is a simple correspondence between a query in one design & one in the other. So we can write your query.

In SQL the tradition is to use NULL as a special value instead of 'xxx'. The table meaning would be "client [clientid] named [firstname] [lastname] has either said they are willing to pay [maxrent] or has not said how much they are willing to pay and [maxrent] is NULL". Operators in SQL treat NULL specially--they aren't the same operators as the relational or everyday ones with the same names.

Notice that the NULL-free designs have more but simpler base tables & meanings. Any design with NULL can be rearranged to one without. All four of these designs can be rearranged to any other. There are other styles of NULL-free designs that are more similar to designs with NULL.

(A certain textbook that your table is surely drawn from allows maxrent to be NULL. They also never clearly say what rows go in their tables. But the idea is that every table that can have NULLs has a meaning that is the obvious transformation of the obvious null-free meaning. They wrongly & fuzzily say, "Without nulls, it becomes necessary to introduce false data to represent this state or to add additional attributes that may not be meaningful to the user." They also say a lot of typical fuzzy unhelpful things like "null is not a value".)

(It's not clear what you mean by "unknown information" or by "expressing" something that is not known or "an empty data point". One can express that one doesn't know the value(s) satisfying a condition. But every row in a table asserts the statement made from its meaning and every row not in it (of the appropriate type) asserts the negation of the statement made from its meaning.)

Re relational querying.
What to do with null values when modeling and normalizing?



来源:https://stackoverflow.com/questions/53022130/how-to-express-no-information-in-relational-algebra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!