Apache Presto – Basic SQL Operations

In this chapter, we will discuss how to create and execute queries on Presto. Let us go through Presto supported basic data types.

Basic Data Types

The following table describes the basic data types of Presto.

S.NoData type & Description
1.VARCHARVariable length character data
2.BIGINTA 64-bit signed integer
3.DOUBLEA 64-bit floating point double precision value
4.DECIMALA fixed precision decimal number. For example DECIMAL(10,3) – 10 is precision, i.e. total number of digits and 3 is scale value represented as fractional point. Scale is optional and default value is 0
5.BOOLEANBoolean values true and false
6.VARBINARYVariable length binary data
7.JSONJSON data
8.DATEDate data type represented as year-month-day
9.TIME, TIMESTAMP, TIMESTAMP with TIME ZONETIME – Time of the day (hour-min-sec-millisecond)TIMESTAMP – Date and time of the dayTIMESTAMP with TIME ZONE – Date and time of the day with time zone from the value
10.INTERVALStretch or extend date and time data types
11.ARRAYArray of the given component type. For example, ARRAY[5,7]
12.MAPMap between the given component types. For example, MAP(ARRAY[‘one’,’two’],ARRAY[5,7])
13.ROWRow structure made up of named fields

Presto − Operators

Presto operators are listed in the following table.

S.NoOperator & Description
1.Arithmetic operatorPresto supports arithmetic operators such as +, -, *, /, %
2.Relational operator<,>,<=,>=,=,<>
3.Logical operatorAND, OR, NOT
4.Range operatorRange operator is used to test the value in a specific range. Presto supports BETWEEN, IS NULL, IS NOT NULL, GREATEST and LEAST
5.Decimal operatorBinary arithmetic decimal operator performs binary arithmetic operation for decimal type Unary decimal operator − The – operator performs negation
6.String operatorThe ‘||’ operator performs string concatenation
7.Date and time operatorPerforms arithmetic addition and subtraction operations on date and time data types
8.Array operatorSubscript operator[] – access an element of an arrayConcatenation operator || – concatenate an array with an array or an element of the same type
9.Map operatorMap subscript operator [] – retrieve the value corresponding to a given key from a map

Leave a Reply