我有两张表const MyElement = (props) => {
const thing = <span><li>Thing 1</li><li>Thing 2</li></span>;
return (
<ul>
<li>First</li>
{condition ? thing.props.children : null}
<li>Second</li>
</ul>
);
}
和free_time
。两者都包含tsranges。
如何在appointment
中“减去”appointment
的差异后,如何编写确定实际空闲时间的查询(或函数)?
freetime
我希望结果如下:
INSERT INTO free_time(freetime)
VALUES('[2017-04-19 09:00, 2017-04-19 12:30)');
INSERT INTO appointment(appointment)
VALUES('[2017-04-19 10:30, 2017-04-19 11:30)');
答案 0 :(得分:1)
你必须从the docs
分开范围如果结果范围需要包含两个不相交的子范围,则union和difference运算符将失败,因为无法表示这样的范围。
为此,您可以使用lower
, and upper
SELECT tsrange( lower(freetime), lower(appointment) ) AS before_appointment,
tsrange( upper(appointment), upper(freetime) ) AS after_appointment
FROM ( VALUES
(
'[2017-04-19 09:00, 2017-04-19 12:30)'::tsrange,
'[2017-04-19 10:30, 2017-04-19 11:30)'::tsrange
)
) AS t(freetime,appointment)
WHERE freetime @> appointment;
before_appointment | after_appointment
-----------------------------------------------+-----------------------------------------------
["2017-04-19 09:00:00","2017-04-19 10:30:00") | ["2017-04-19 11:30:00","2017-04-19 12:30:00")
(1 row)