4 SELECT num_nonnulls(NULL);
10 SELECT num_nonnulls('1');
16 SELECT num_nonnulls(NULL::text);
22 SELECT num_nonnulls(NULL::text, NULL::int);
28 SELECT num_nonnulls(1, 2, NULL::text, NULL::point, '', int8 '9', 1.0 / NULL);
34 SELECT num_nonnulls(VARIADIC '{1,2,NULL,3}'::int[]);
40 SELECT num_nonnulls(VARIADIC '{"1","2","3","4"}'::text[]);
46 SELECT num_nonnulls(VARIADIC ARRAY(SELECT CASE WHEN i <> 40 THEN i END FROM generate_series(1, 100) i));
52 SELECT num_nulls(NULL);
58 SELECT num_nulls('1');
64 SELECT num_nulls(NULL::text);
70 SELECT num_nulls(NULL::text, NULL::int);
76 SELECT num_nulls(1, 2, NULL::text, NULL::point, '', int8 '9', 1.0 / NULL);
82 SELECT num_nulls(VARIADIC '{1,2,NULL,3}'::int[]);
88 SELECT num_nulls(VARIADIC '{"1","2","3","4"}'::text[]);
94 SELECT num_nulls(VARIADIC ARRAY(SELECT CASE WHEN i <> 40 THEN i END FROM generate_series(1, 100) i));
101 SELECT num_nonnulls(VARIADIC NULL::text[]);
107 SELECT num_nonnulls(VARIADIC '{}'::int[]);
113 SELECT num_nulls(VARIADIC NULL::text[]);
119 SELECT num_nulls(VARIADIC '{}'::int[]);
125 -- should fail, one or more arguments is required
126 SELECT num_nonnulls();
127 ERROR: function num_nonnulls() does not exist
128 LINE 1: SELECT num_nonnulls();
130 HINT: No function matches the given name and argument types. You might need to add explicit type casts.
132 ERROR: function num_nulls() does not exist
133 LINE 1: SELECT num_nulls();
135 HINT: No function matches the given name and argument types. You might need to add explicit type casts.
137 -- pg_log_backend_memory_contexts()
139 -- Memory contexts are logged and they are not returned to the function.
140 -- Furthermore, their contents can vary depending on the timing. However,
141 -- we can at least verify that the code doesn't fail.
143 SELECT * FROM pg_log_backend_memory_contexts(pg_backend_pid());
144 pg_log_backend_memory_contexts
145 --------------------------------
150 -- Test some built-in SRFs
152 -- The outputs of these are variable, so we can't just print their results
153 -- directly, but we can at least verify that the code doesn't fail.
155 select setting as segsize
156 from pg_settings where name = 'wal_segment_size'
158 select count(*) > 0 as ok from pg_ls_waldir();
164 -- Test ProjectSet as well as FunctionScan
165 select count(*) > 0 as ok from (select pg_ls_waldir()) ss;
171 -- Test not-run-to-completion cases.
172 select * from pg_ls_waldir() limit 0;
173 name | size | modification
174 ------+------+--------------
177 select count(*) > 0 as ok from (select * from pg_ls_waldir() limit 1) ss;
183 select (w).size = :segsize as ok
184 from (select pg_ls_waldir() w) ss where length((w).name) = 24 limit 1;
190 select count(*) >= 0 as ok from pg_ls_archive_statusdir();
196 select * from (select pg_ls_dir('.') a) a where a = 'base' limit 1;
202 select * from (select (pg_timezone_names()).name) ptn where name='UTC' limit 1;
208 select count(*) > 0 from
209 (select pg_tablespace_databases(oid) as pts from pg_tablespace
210 where spcname = 'pg_default') pts
211 join pg_database db on pts.pts = db.oid;
218 -- Test adding a support function to a subject function
220 CREATE FUNCTION my_int_eq(int, int) RETURNS bool
221 LANGUAGE internal STRICT IMMUTABLE PARALLEL SAFE
223 -- By default, planner does not think that's selective
225 SELECT * FROM tenk1 a JOIN tenk1 b ON a.unique1 = b.unique1
226 WHERE my_int_eq(a.unique2, 42);
228 ----------------------------------------------
230 Hash Cond: (b.unique1 = a.unique1)
231 -> Seq Scan on tenk1 b
233 -> Seq Scan on tenk1 a
234 Filter: my_int_eq(unique2, 42)
237 -- With support function that knows it's int4eq, we get a different plan
238 ALTER FUNCTION my_int_eq(int, int) SUPPORT test_support_func;
240 SELECT * FROM tenk1 a JOIN tenk1 b ON a.unique1 = b.unique1
241 WHERE my_int_eq(a.unique2, 42);
243 -------------------------------------------------
245 -> Seq Scan on tenk1 a
246 Filter: my_int_eq(unique2, 42)
247 -> Index Scan using tenk1_unique1 on tenk1 b
248 Index Cond: (unique1 = a.unique1)
251 -- Also test non-default rowcount estimate
252 CREATE FUNCTION my_gen_series(int, int) RETURNS SETOF integer
253 LANGUAGE internal STRICT IMMUTABLE PARALLEL SAFE
254 AS $$generate_series_int4$$
255 SUPPORT test_support_func;
257 SELECT * FROM tenk1 a JOIN my_gen_series(1,1000) g ON a.unique1 = g;
259 ----------------------------------------
261 Hash Cond: (g.g = a.unique1)
262 -> Function Scan on my_gen_series g
264 -> Seq Scan on tenk1 a
268 SELECT * FROM tenk1 a JOIN my_gen_series(1,10) g ON a.unique1 = g;
270 -------------------------------------------------
272 -> Function Scan on my_gen_series g
273 -> Index Scan using tenk1_unique1 on tenk1 a
274 Index Cond: (unique1 = g.g)