cloud-fan commented on a change in pull request #28237: URL: https://github.com/apache/spark/pull/28237#discussion_r411095492
########## File path: docs/sql-ref-literals.md ########## @@ -0,0 +1,506 @@ +--- +layout: global +title: Literals +displayTitle: Literals +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +A literal (also known as a constant) represents a fixed data value. Spark SQL supports the following literals: + + * [String Literal](#string-literal) + * [Null Literal](#null-literal) + * [Boolean Literal](#boolean-literal) + * [Numeric Literal](#numeric-literal) + * [Datetime Literal](#datetime-literal) + * [Interval Literal](#interval-literal) + +### String Literal + +A string literal is used to specify a character string value. + +#### Syntax + +{% highlight sql %} +'c [ ... ]' | "c [ ... ]" +{% endhighlight %} + +#### <em>Parameters</em> + +<dl> + <dt><code><em>c</em></code></dt> + <dd> + One character from the character set. Use <code>\</code> to escape special characters (e.g., <code>'</code> or <code>\</code>). + </dd> +</dl> + +#### <em>Examples</em> + +{% highlight sql %} +SELECT 'Hello, World!' AS col; + +-------------+ + | col| + +-------------+ + |Hello, World!| + +-------------+ + +SELECT "SPARK SQL" AS col; + +---------+ + | col| + +---------+ + |Spark SQL| + +---------+ + +SELECT SELECT 'it\'s $10.' AS col; + +---------+ + | col| + +---------+ + |It's $10.| + +---------+ +{% endhighlight %} + +### Null Literal + +A null literal is used to specify a null value. + +#### Syntax + +{% highlight sql %} +NULL +{% endhighlight %} + +#### Examples + +{% highlight sql %} +SELECT NULL AS col; + +----+ + | col| + +----+ + |NULL| + +----+ +{% endhighlight %} + +### Boolean Literal + +A boolean literal is used to specify a boolean value. + +#### Syntax + +{% highlight sql %} +TRUE | FALSE +{% endhighlight %} + +#### Examples + +{% highlight sql %} +SELECT TRUE AS col; + +----+ + | col| + +----+ + |true| + +----+ +{% endhighlight %} + +### Numeric Literal + +A numeric literal is used to specify a fixed or floating-point number. + +#### Integer Literal + +#### Syntax + +{% highlight sql %} +[ + | - ] digit [ ... ] [ L | S | Y ] +{% endhighlight %} + +#### Parameters + +<dl> + <dt><code><em>digit</em></code></dt> + <dd> + Any numeral from 0 to 9. + </dd> +</dl> +<dl> + <dt><code><em>L</em></code></dt> + <dd> + Case insensitive, indicates <code>BIGINT</code>, which is a 8-byte signed integer number. + </dd> +</dl> +<dl> + <dt><code><em>S</em></code></dt> + <dd> + Case insensitive, indicates <code>SMALLINT</code>, which is a 2-byte signed integer number. + </dd> +</dl> +<dl> + <dt><code><em>Y</em></code></dt> + <dd> + Case insensitive, indicates <code>TINYINT</code>, which is a 1-byte signed integer number. + </dd> +</dl> +<dl> + <dt><code><em>default (no postfix)</em></code></dt> + <dd> + Indicates a 4-byte signed integer number. + </dd> +</dl> + +#### Examples + +{% highlight sql %} +SELECT -2147483648 AS col; + +-----------+ + | col| + +-----------+ + |-2147483648| + +-----------+ + +SELECT 9223372036854775807l AS col; + +-------------------+ + | col| + +-------------------+ + |9223372036854775807| + +-------------------+ + +SELECT -32Y AS col; + +---+ + |col| + +---+ + |-32| + +---+ + +SELECT 482S AS col; + +---+ + |col| + +---+ + |482| + +---+ +{% endhighlight %} + +#### Decimal Literal + +#### Syntax + +{% highlight sql %} +[ + | - ] { digit [ ... ] . [ digit [ ... ] ] | . digit [ ... ] } +{% endhighlight %} + +#### Parameters + +<dl> + <dt><code><em>digit</em></code></dt> + <dd> + Any numeral from 0 to 9. + </dd> +</dl> + +#### Examples + +{% highlight sql %} +SELECT 12.578 AS col; + +------+ + | col| + +------+ + |12.578| + +------+ + +SELECT -0.1234567 AS col; + +----------+ + | col| + +----------+ + |-0.1234567| + +----------+ + +SELECT -.1234567 AS col; Review comment: `123.` is also a decimal, right? which is the same as `123.0` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org