# Literals¶

Literals represent constant values.

SQream DB contains several types of literals:

• Number literals - define numbers such as 1.3, -5
• String literals - define text values like 'Foxes are cool', '1997-01-01'
• Typed literals - define values with explicit types like (3.0 :: float)
• Other constants - predfined values like NULL or TRUE

## Number literals¶

A number literal can be expressed in the following way:

number_literal ::=
[+-] digits
| digits . [ digits ] [ e [+-] digits ]
| [ digits ] . digits [ e [+-] digits ]
| digits e[+-]digits


### Examples¶

1234

1234.56

12.

.34

123.56e-45

0.23

3.141

42


Note

The actual data type of the value changes based on context, the format used, and the value itself. For example, any number containing the decimal point will be considered FLOAT by default. Any whole number will considered INT, unless the value is larger than the maximum value, in which case the type will become a BIGINT.

## String literals¶

String literals are string (text) values, encoded either in ASCII or UTF-8.

A string literal is quoted with single quotes (') or dollars ($$) Tip To use a single quote in a string, repeat the single quote twice. See examples below. ### Examples¶ 'This is an example of a string' 'Hello? Is it me you''re looking for?' -- Repeated single quotes are treated as a single quote$$That is my brother's company's CEO's son's dog's toy -- Dollar-quoted

'1997-01-01' -- This is a string


The actual data type of the value changes based on context, the format used, and the value itself. In the example below, the first value is interpreted as a DATE, while the second is interpreted as a VARCHAR.

INSERT INTO cool_dates(date_col, reason) VALUES ('1955-11-05', 'Doc Brown discovers flux capacitor');


## Typed literals¶

A typed literal allows the creation of any data type using either of the following syntaxes:

CAST(literal AS type_name)
-- or
literal :: type_name


### Syntax reference¶

typed_literal ::=
cast(literal AS type_name)
| literal :: type_name

literal ::=
string_literal
| number_literal
| NULL | TRUE | FALSE

type_name ::=

BOOL
| TINYINT
| SMALLINT
| INT
| BIGINT
| FLOAT
| REAL
| DATE
| DATETIME
| VARCHAR ( digits )
| TEXT ( digits )


### Examples¶

'1955-11-05' :: date

'TRUE' :: BOOL

CAST('2300' as BIGINT)

CAST(42 :: FLOAT)


## Other constants¶

• TRUE and FALSE are interpreted as values of type BOOL.
• NULL - which has no type by itself. The type is inferred from context during query compilation.