nested hstore
[hstore.git] / sql / types.sql
1 SELECT '"foo"=>true'::hstore;
2 SELECT 'foo=>true'::hstore;
3 SELECT '"true"=>true'::hstore;
4 SELECT 'true=>true'::hstore;
5 SELECT '"t"=>true'::hstore;
6 SELECT 't=>true'::hstore;
7 SELECT '"false"=>true'::hstore;
8 SELECT 'false=>true'::hstore;
9 SELECT '"f"=>true'::hstore;
10 SELECT 'f=>true'::hstore;
11
12 SELECT '"foo"=>false'::hstore;
13 SELECT 'foo=>false'::hstore;
14 SELECT '"false"=>false'::hstore;
15 SELECT 'false=>false'::hstore;
16 SELECT '"t"=>false'::hstore;
17 SELECT 't=>false'::hstore;
18 SELECT '"false"=>false'::hstore;
19 SELECT 'false=>false'::hstore;
20 SELECT '"f"=>false'::hstore;
21 SELECT 'f=>false'::hstore;
22
23 SELECT '"1"=>x'::hstore;
24 SELECT '1=>x'::hstore;
25 SELECT 'foo=>1'::hstore;
26 SELECT 'foo=>1.'::hstore;
27 SELECT 'foo=>1.0'::hstore;
28 SELECT 'foo=>1.01'::hstore;
29 SELECT 'foo=>1.01e'::hstore;
30 SELECT 'foo=>1.01e1'::hstore;
31 SELECT 'foo=>1.01e+1'::hstore;
32 SELECT 'foo=>1.01e-1'::hstore;
33 SELECT 'foo=>.1'::hstore;
34 SELECT 'foo=>.1e'::hstore;
35 SELECT 'foo=>.1e1'::hstore;
36 SELECT 'foo=>.1e+1'::hstore;
37 SELECT 'foo=>.1e-1'::hstore;
38 SELECT 'foo=>0.1e-1'::hstore;
39 SELECT 'foo=>00.1e-1'::hstore;
40
41 SELECT 'foo=>+1'::hstore;
42 SELECT 'foo=>+1.'::hstore;
43 SELECT 'foo=>+1.0'::hstore;
44 SELECT 'foo=>+1.01'::hstore;
45 SELECT 'foo=>+1.01e'::hstore;
46 SELECT 'foo=>+1.01e1'::hstore;
47 SELECT 'foo=>+1.01e+1'::hstore;
48 SELECT 'foo=>+1.01e-1'::hstore;
49 SELECT 'foo=>+.1'::hstore;
50 SELECT 'foo=>+.1e'::hstore;
51 SELECT 'foo=>+.1e1'::hstore;
52 SELECT 'foo=>+.1e+1'::hstore;
53 SELECT 'foo=>+.1e-1'::hstore;
54
55 SELECT 'foo=>-1'::hstore;
56 SELECT 'foo=>-1.'::hstore;
57 SELECT 'foo=>-1.0'::hstore;
58 SELECT 'foo=>-1.01'::hstore;
59 SELECT 'foo=>-1.01e'::hstore;
60 SELECT 'foo=>-1.01e1'::hstore;
61 SELECT 'foo=>-1.01e+1'::hstore;
62 SELECT 'foo=>-1.01e-1'::hstore;
63 SELECT 'foo=>-.1'::hstore;
64 SELECT 'foo=>-.1e'::hstore;
65 SELECT 'foo=>-.1e1'::hstore;
66 SELECT 'foo=>-.1e+1'::hstore;
67 SELECT 'foo=>-.1e-1'::hstore;
68
69 SELECT 'foo=>1e2000'::hstore;
70
71 SELECT 'foo=>1e12, bar=>x'::hstore ^> 'foo';
72 SELECT 'foo=>1e12, bar=>x'::hstore ^> 'bar';
73 SELECT 'foo=>1e12, bar=>x'::hstore ^> 0;
74 SELECT 'foo=>1e12, bar=>x'::hstore ^> 1;
75
76 SELECT '[foo, 1e12, bar, x]'::hstore ^> 'foo';
77 SELECT '[foo, 1e12, bar, x]'::hstore ^> 'bar';
78 SELECT '[foo, 1e12, bar, x]'::hstore ^> 0;
79 SELECT '[foo, 1e12, bar, x]'::hstore ^> 1;
80
81 SELECT 'foo=>{x, 1e-12}'::hstore #^> '{foo, 0}';
82 SELECT 'foo=>{x, 1e-12}'::hstore #^> '{foo, 1}';
83
84 SELECT 'foo=>t, bar=>x'::hstore ?> 'foo';
85 SELECT 'foo=>t, bar=>x'::hstore ?> 'bar';
86 SELECT 'foo=>t, bar=>x'::hstore ?> 0;
87 SELECT 'foo=>t, bar=>x'::hstore ?> 1;
88
89 SELECT '[foo, t, bar, x]'::hstore ?> 'foo';
90 SELECT '[foo, t, bar, x]'::hstore ?> 'bar';
91 SELECT '[foo, t, bar, x]'::hstore ?> 0;
92 SELECT '[foo, t, bar, x]'::hstore ?> 1;
93
94 SELECT 'foo=>{x, t}'::hstore #?> '{foo, 0}';
95 SELECT 'foo=>{x, t}'::hstore #?> '{foo, 1}';
96
97 SELECT 'foo=>f, bar=>x'::hstore ?> 'foo';
98 SELECT 'foo=>f, bar=>x'::hstore ?> 'bar';
99 SELECT 'foo=>f, bar=>x'::hstore ?> 0;
100 SELECT 'foo=>f, bar=>x'::hstore ?> 1;
101
102 SELECT '[foo, f, bar, x]'::hstore ?> 'foo';
103 SELECT '[foo, f, bar, x]'::hstore ?> 'bar';
104 SELECT '[foo, f, bar, x]'::hstore ?> 0;
105 SELECT '[foo, f, bar, x]'::hstore ?> 1;
106
107 SELECT 'foo=>{x, f}'::hstore #?> '{foo, 0}';
108 SELECT 'foo=>{x, f}'::hstore #?> '{foo, 1}';
109
110
111 SELECT hstore_typeof('a=>b') AS hash;
112 SELECT hstore_typeof('{a=>b}') AS hash;
113 SELECT hstore_typeof('{a, b}') AS array;
114 SELECT hstore_typeof('{{a=>b}}') AS array;
115 SELECT hstore_typeof('[a, b]') AS array;
116 SELECT hstore_typeof('') AS "NULL";
117 SELECT hstore_typeof('NULL') AS "null";
118 SELECT hstore_typeof('1.0') AS numeric;
119 SELECT hstore_typeof('t') AS bool;
120 SELECT hstore_typeof('f') AS bool;
121
122 SELECT hstore('xxx', 't'::bool);
123 SELECT hstore('xxx', 'f'::bool);
124
125 SELECT hstore('xxx', 3.14);
126 SELECT hstore('xxx', 3.14::numeric);
127 SELECT hstore('xxx', '3.14'::numeric);
128
129 SELECT hstore(NULL);
130 SELECT hstore('NULL');
131
132 SELECT hstore('t'::bool) AS "true", hstore('f'::bool) AS "false";
133
134 SELECT hstore(3.14), hstore(3.14::numeric), hstore('3.14'::numeric);
135
136 SELECT hstore('xxx', 'foo=>t, bar=>3.14, zzz=>xxx'::hstore);
137
138 SELECT array_to_hstore('{{1,1,4},{23,3,5}}'::int2[]);
139 SELECT array_to_hstore('{{1,1,4},{23,3,5}}'::int4[]);
140 SELECT array_to_hstore('{{1,1,4},{23,3,5}}'::int8[]);
141 SELECT array_to_hstore('{{1,1,4},{23,3,5}}'::float4[]);
142 SELECT array_to_hstore('{{1,1,4},{23,3,5}}'::float8[]);
143 SELECT array_to_hstore('{{1,1,f},{f,t,NULL}}'::bool[]);
144 SELECT array_to_hstore('{{1,1,4},{23,3,5}}'::text[]);
145 SELECT array_to_hstore('{{1,1,4},{23,3,5}}'::varchar[]);
146
147 SELECT array_to_hstore('{{{1,11},{1,1},{4,41}},{{23,231},{3,31},{5,51}}}'::int4[]);
148 SELECT hstore('array', array_to_hstore('{{{1,11},{1,1},{4,41}},{{23,231},{3,31},{5,51}}}'::int4[]));
149
150 SELECT 'a=>"00012333", b=>"12233", c=>00012333, d=>12233'::hstore;
151 SELECT hstore_to_json('a=>"00012333", b=>"12233", c=>00012333, d=>12233'::hstore);
152 SELECT hstore_to_json_loose('a=>"00012333", b=>"12233", c=>00012333, d=>12233'::hstore);