2021-08-28 13:46:32 +03:00
|
|
|
================================================================================
|
|
|
|
string
|
|
|
|
================================================================================
|
|
|
|
SELECT 'hello';
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(string))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
nested select
|
|
|
|
================================================================================
|
|
|
|
SELECT (SELECT 'hello');
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(string))))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
many
|
|
|
|
================================================================================
|
|
|
|
SELECT 1234, -25, TRUE, FALSE, NULL, *;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(number))
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(minus)
|
|
|
|
(number)))
|
|
|
|
(select_item
|
|
|
|
(true))
|
|
|
|
(select_item
|
|
|
|
(false))
|
|
|
|
(select_item
|
|
|
|
(null))
|
|
|
|
(select_item
|
|
|
|
(star))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
identifiers
|
|
|
|
================================================================================
|
|
|
|
SELECT foo, foo.bar;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(identifier))
|
|
|
|
(select_item
|
|
|
|
(identifier))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
binary_expression
|
|
|
|
================================================================================
|
|
|
|
SELECT a + b - c / d * e % f;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(identifier))
|
|
|
|
(op_expression
|
|
|
|
(op_expression
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(identifier))
|
|
|
|
(identifier))
|
|
|
|
(identifier))))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
unary prec over binary
|
|
|
|
================================================================================
|
|
|
|
SELECT -22 + - (5 + 1);
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(op_expression
|
|
|
|
(minus)
|
|
|
|
(number))
|
|
|
|
(op_expression
|
|
|
|
(minus)
|
|
|
|
(op_expression
|
|
|
|
(number)
|
|
|
|
(number)))))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
nested parens
|
|
|
|
================================================================================
|
|
|
|
SELECT ((((24 + 24))));
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(number)
|
|
|
|
(number)))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
logical expressions
|
|
|
|
================================================================================
|
|
|
|
SELECT 1 - 2 AND TRUE OR (5 = 2);
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(op_expression
|
|
|
|
(op_expression
|
|
|
|
(number)
|
|
|
|
(number))
|
|
|
|
(and)
|
|
|
|
(true))
|
|
|
|
(or)
|
|
|
|
(op_expression
|
|
|
|
(number)
|
|
|
|
(comparison_op)
|
|
|
|
(number))))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
function call
|
|
|
|
================================================================================
|
|
|
|
SELECT foo.bar(param) + baz();
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(function_call
|
|
|
|
(identifier)
|
|
|
|
(identifier))
|
|
|
|
(function_call
|
|
|
|
(identifier))))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
nested function call
|
|
|
|
================================================================================
|
|
|
|
SELECT coalesce(null, nullif(false, true), ops.my_fn(5));
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(function_call
|
|
|
|
(identifier)
|
|
|
|
(null)
|
|
|
|
(function_call
|
|
|
|
(identifier)
|
|
|
|
(false)
|
|
|
|
(true))
|
|
|
|
(function_call
|
|
|
|
(identifier)
|
|
|
|
(number))))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
casting
|
|
|
|
================================================================================
|
|
|
|
SELECT 1::text;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(number)
|
|
|
|
(cast)
|
|
|
|
(identifier)))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
string concatenation
|
|
|
|
================================================================================
|
|
|
|
SELECT 'hello' || 1 || now();
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(op_expression
|
|
|
|
(string)
|
|
|
|
(other_op)
|
|
|
|
(number))
|
|
|
|
(other_op)
|
|
|
|
(function_call
|
|
|
|
(identifier))))))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
string quote
|
|
|
|
================================================================================
|
|
|
|
SELECT 'hello' || 'quote''s everywh''ere';
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(string)
|
|
|
|
(other_op)
|
|
|
|
(string)))))
|
2021-08-31 21:29:46 +03:00
|
|
|
|
|
|
|
================================================================================
|
|
|
|
is null, isnull, is not null, notnull
|
|
|
|
================================================================================
|
|
|
|
SELECT
|
|
|
|
foo is null,
|
|
|
|
foo is not null,
|
|
|
|
foo isnull,
|
|
|
|
foo notnull;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_null)))
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_null)))
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_null)))
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(comparison_null)))))
|
|
|
|
|
2021-08-31 21:30:45 +03:00
|
|
|
================================================================================
|
|
|
|
time expressions
|
|
|
|
================================================================================
|
|
|
|
SELECT
|
|
|
|
foo::interval,
|
|
|
|
foo at time zone 'utc',
|
|
|
|
interval '1 day',
|
|
|
|
interval '1' hour to second,
|
|
|
|
interval '1' day + interval '3' month;
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(select_statement
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(identifier)
|
|
|
|
(cast)
|
|
|
|
(identifier)))
|
|
|
|
(select_item
|
|
|
|
(time_expression
|
|
|
|
(identifier)
|
|
|
|
(string)))
|
|
|
|
(select_item
|
|
|
|
(time_expression
|
|
|
|
(string)))
|
|
|
|
(select_item
|
|
|
|
(time_expression
|
|
|
|
(string)))
|
|
|
|
(select_item
|
|
|
|
(op_expression
|
|
|
|
(time_expression
|
|
|
|
(string))
|
|
|
|
(time_expression
|
|
|
|
(string))))))
|