File: test_value_functions.test

package info (click to toggle)
duckdb 1.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 558
file content (79 lines) | stat: -rw-r--r-- 1,715 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# name: test/sql/parser/test_value_functions.test
# description: Test SQL value functions
# group: [parser]

require no_extension_autoloading "FIXME: Unimplemented type for cast (TIMESTAMP WITH TIME ZONE -> DATE)"

statement ok
PRAGMA enable_verification

# by default these columns can be used as per usual
query I
SELECT user FROM (VALUES ('hello world')) t(user)
----
hello world

# if the column is not found they are turned into the SQL value function
query I
SELECT user
----
duckdb

query I
SELECT UsEr
----
duckdb

# Issue #10363 - we also prefer table-as-struct over value functions
query I
SELECT user FROM (VALUES (42)) user(x)
----
{'x': 42}

# run all SQL value functions
# need to run without verification since CURRENT_TIME etc break verification
statement ok
PRAGMA disable_verification

require icu

foreach value_function current_catalog current_date current_schema current_role current_time current_timestamp current_user localtime localtimestamp session_user user

statement ok
SELECT ${value_function}

endloop

statement error
SELECT useRrr
----
useRrr

# value function in having
query II
select
  1 as one,
  max(cast('1000-05-01 00:00:00' as timestamp)) as mt
group by one
having max(cast('1000-05-01 00:00:00' as timestamp))  <= current_timestamp;
----
1	1000-05-01 00:00:00

query II
select a as "b", "b" + 1 from (VALUES (84), (42)) t(a) ORDER BY ALL;
----
42	43
84	85

# value function conflict in ORDER BY
query I
select a as "CURRENT_TIMESTAMP" from (VALUES (84), (42)) t(a) order by "CURRENT_TIMESTAMP" + 1;
----
42
84

# value function conflict in WHERE
query I
select a as localtime from (VALUES ('2018-01-01'), ('2022-01-01')) t(a) where localtime >= '2020-01-01'
----
2022-01-01