如果有至少一個匹配,regexp_matches的結果是數組:
t=# select regexp_matches(tablename, '^pg(?!s)', 'g') from pg_tables limit 1;
regexp_matches
----------------
{pg}
(1 row)
,如果你沒有比賽 - the result is not empty array, but no rows:
功能可以不返回行,一列,或多個行(見下面的克 標誌)
t=# select regexp_matches(tablename, '^http(?!s)', 'g') from pg_tables;
regexp_matches
----------------
(0 rows)
,最後array_length無行沒有給出行:
t=# with no_rows_returned as (select ARRAY[1,2] aa from pg_tables where false)
select array_length(aa,1) from no_rows_returned;
array_length
--------------
(0 rows)
而且這種行爲也不例外,沒有行另一個例子,而不WHERE
條款:
t=# select json_agg(tablename) filter (where tablename = 'no such table') from pg_tables;
json_agg
----------
(1 row)
或
t=# select unnest(array_remove(array_remove(ARRAY[1,2],1),2));
unnest
--------
(0 rows)