我已经定义了这个功能对所有列执行一个函数,修剪尾随空白:在选择查询
select trim_trailing_whitespace(SomeColumn), count(*) from MyTable group by SomeColumn;
但是:
create or replace function trim_trailing_whitespace(value text) returns text as $$ begin return regexp_replace(value, '\s+$', ''); end; $$ language plpgsql immutable;
它在查询中使用像这样的时候正常工作
select trim_trailing_whitespace(*) from MyTable;
:,当我尝试用通配符来利用它,像这样失败第1行:从MyTable中选择trim_trailing_whitespace(*);
提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。
如何在选择查询中的所有列上执行函数?在我的情况下,我想在执行选择时从每列中删除尾随的空白。
或使用row_to_json传递数据作为JSON ...记住,除非你的函数返回一个特定类型的行,JSON很可能是最好的选择之一,考虑到它如何被使用。 –
这看起来很有希望,但我无法让它在具有多列的行上工作。 –