Skip to Content
Trino 权威指南:原书第2版
book

Trino 权威指南:原书第2版

by Matt Fuller, Manfred Moser, Martin Traverso
July 2023
Intermediate to advanced
278 pages
5h 40m
Chinese
China Machine Press
Content preview from Trino 权威指南:原书第2版
高级
SQL
特性
|
167
单目运算符的用法:运算符
操作数
对于双目运算符和单目运算符,输入的操作数可以是一个运算符树运算的结果。例如,
2×2×2
中,第一个运算符
2×2
的结果被输入第二个乘法运算符中。
在本章的以下几节中,你将详细了解
Trino
所支持的众多函数和运算符。
9.2
标量函数和运算符
抽象地讲,
SQL
中的标量函数将一个或多个单值作为输入参数,根据输入的参数执行一
个操作,然后产生一个单值。例如,
power(x, p)
函数返回
x
p
次幂:
SELECT power(2, 3);
_col0
-------
8.0
(1 row)
当然,你可以用乘法运算符来实现同样的目的,在本例中,
2×2×2
也会产生值
8
。但是,
使用函数可以将逻辑封装起来,使其更容易在
SQL
中重复使用。此外还有其他好处,比
如减少出错的可能和优化函数的执行。
只要语义正确,标量函数可以用在
SQL
语句中任何可以使用表达式的地方。例如,你
可以写一个
SQL
查询
SELECT * FROM page_views WHERE power(2, 3)
。它可以通过语
法检查,但在语义分析时会失败,因为
power
函数的返回类型是
DOUBLE
而不是所需的
BOOLEAN
。可以将
SQL
查询写成
SELECT * FROM page_views WHERE power(2, 3) = 8
虽然它可能没有实际用处,但语义上是正确的。
Trino
包含了一组可以立即使用的内置函数和运算符。在本节中,你了解了常见用法并
着重学习了有趣的部分。我们并没有列举每一个函数和运算符,因为本章无意作为全面 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

What Successful Brick-and-Mortar Retailers Get Right

What Successful Brick-and-Mortar Retailers Get Right

Rob Angell
Three Essentials for Agentic AI Security

Three Essentials for Agentic AI Security

Paolo Dal Cin, Daniel Kendzior, Yusof Seedat, Renato Marinho
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9787111731603