Set Returning Function をスカラー関数として使用することの副作用です。Set Returning Functions は、スカラー関数ではなくテーブルを返し、通常は FROM 句で使用されます。(いくつかの理由から) スカラー関数のように使用できますが、非常に奇妙な副作用が時々発生します。通常、これらの関数をスカラー関数の位置で使用することはありません。
postgres=# select * from foo;
a
---
1
2
(2行)
postgres=# select a, generate_series(1,0) from foo;
| | generate_series
---+-----------------
(0行)
postgres=# select a, generate_series(1,1) from foo;
| | generate_series
---+-----------------
1 | 1
2 | 1
(2行)
postgres=# select a, generate_series(1,2) from foo;
| | generate_series
---+-----------------
1 | 1
1 | 2
2 | 1
2 | 2
(4行)
おそらく、正規表現で部分文字列関数を使用するでしょう。これはスカラー関数です:
postgres=# select 'Some string', substring('Ahoj29' from '^[0-9]+');
?桁?| | 部分文字列
---+-----------
いくつかの文字列 |
(1行)
postgres=# select 'Some string', substring('Ahoj29' from '[0-9]+');
?桁?| | 部分文字列
---+-----------
いくつかの文字列 | 29
(1行)