在下面的示例中,如果我查询给出特定ident
的视图,那么它会正确返回并说订单已完成。
如果我然后要求所有未完成的订单,则返回ident
它明显看到WAS完成。这怎么可能/
# select complete from orders_plus where ident = 8410;
complete
----------
t
(1 row)
# select ident,complete from orders_plus where complete = false;
ident | complete
-------+----------
8402 | f
8410 | f
8414 | f
(3 rows)
以下是视图的定义:
# \d+ orders_plus
View "public.orders_plus"
Column | Type | Modifiers | Storage | Description
--------------+-------------------+-----------+----------+-------------
ident | integer | | plain |
station_id | integer | | plain |
created | date | | plain |
due | date | | plain |
month | date | | plain |
comments | character varying | | extended |
name | character varying | | extended |
ud | real | | plain |
dp | real | | plain |
swrv | real | | plain |
sh | real | | plain |
jmsw | real | | plain |
sw | real | | plain |
prrv | real | | plain |
mhsw | real | | plain |
bmsw | real | | plain |
mp | real | | plain |
pr | real | | plain |
st | real | | plain |
rsw | real | | plain |
rsh | real | | plain |
rpr | real | | plain |
rmp | real | | plain |
total_points | real | | plain |
complete | boolean | | plain |
View definition:
SELECT o.ident, o.station_id, o.created, o.due, o.month, o.comments, o.name,
o.ud, o.dp, o.swrv, o.sh, o.jmsw, o.sw, o.prrv, o.mhsw, o.bmsw, o.mp, o.pr,
o.st, o.rsw, o.rsh, o.rpr, o.rmp, o.total_points,
COALESCE(sum(w.ud) >= o.ud AND sum(w.dp) >= o.dp AND sum(w.swrv) >= o.swrv AND sum(w.sh) >= o.sh AND sum(w.jmsw) >= o.jmsw AND sum(w.sw) >= o.sw AND sum(w.prrv) >= o.prrv AND sum(w.mhsw) >= o.mhsw AND sum(w.bmsw) >= o.bmsw AND sum(w.mp) >= o.mp AND sum(w.pr) >= o.pr AND sum(w.st) >= o.st AND sum(w.rsw) >= o.rsw AND sum(w.rsh) >= o.rsh AND sum(w.rpr) >= o.rpr AND sum(w.rmp) >= o.rmp, false) AS complete
FROM orders o
LEFT JOIN production_work w ON o.ident = w.order_id
GROUP BY o.ident;