创建文本字符串得到错误的输出(postgresql)
Creating text string gets wrong output (postgresql)
我正在尝试创建一个文本字符串供以后在半动态交叉表函数中使用。
只要我不使用格式“numeric(x,x)
,一切都很好
SELECT concat('sign varchar,',(SELECT string_agg(col,',')
FROM (SELECT to_char(generate_series('2016-01-01','2016-01-15', interval '1 week'),'\"iyyy-iw\" numeric(10,2)')col )cols))
输出很奇怪。字母 "i" 替换为数字。
sign varchar,"2015-53" numer5c(10,2),"2016-01" numer6c(10,2),"2016-02" numer6c(10,2)
如何获得以 "numeric(x,x)" 作为列格式的正确文本字符串?
SQLfiddle:http://sqlfiddle.com/#!15/9eecb7db59d16c80417c72d1e1f4fbf1/10313
TIA,
在你的格式字符串中写 "numeric(10,2)"
而不是 numeric(10,2)
。
Ordinary text is allowed in to_char
templates and will be output literally. You can put a substring in double quotes to force it to be interpreted as literal text even if it contains pattern key words.
我正在尝试创建一个文本字符串供以后在半动态交叉表函数中使用。
只要我不使用格式“numeric(x,x)
,一切都很好SELECT concat('sign varchar,',(SELECT string_agg(col,',')
FROM (SELECT to_char(generate_series('2016-01-01','2016-01-15', interval '1 week'),'\"iyyy-iw\" numeric(10,2)')col )cols))
输出很奇怪。字母 "i" 替换为数字。
sign varchar,"2015-53" numer5c(10,2),"2016-01" numer6c(10,2),"2016-02" numer6c(10,2)
如何获得以 "numeric(x,x)" 作为列格式的正确文本字符串?
SQLfiddle:http://sqlfiddle.com/#!15/9eecb7db59d16c80417c72d1e1f4fbf1/10313
TIA,
在你的格式字符串中写 "numeric(10,2)"
而不是 numeric(10,2)
。
Ordinary text is allowed in
to_char
templates and will be output literally. You can put a substring in double quotes to force it to be interpreted as literal text even if it contains pattern key words.