Skip to Content
Presto实战
book

Presto实战

by Matt Fuller, Manfred Moser, Martin Traverso
March 2021
Intermediate to advanced
265 pages
6h 50m
Chinese
Posts & Telecom Press
Content preview from Presto实战
高级
SQL
特性
149
单目运算符
单目运算符接收单个操作数的输入,并产生一个单值结果。与双目运算符一样,运算符
指定了操作数的数据类型必须是什么,结果的数据类型必须是什么。单目运算符写作
算符操作数
对于双目运算符和单目运算符,输入的操作数可以是一个运算符树运算的结果。例如,在
2×2×2
中,第一个运算符
2×2
的结果被输入第二个乘法运算符中。
在本章的以下几节中,你将详细了解
Presto
所支持的众多函数和运算符。
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
,虽然它可 ...
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

大数据项目管理:从规划到实现

大数据项目管理:从规划到实现

Ted Malaska, Jonathan Seidman
机器学习流水线实战

机器学习流水线实战

Hannes Hapke, Catherine Nelson

Publisher Resources

ISBN: 9787115560056