Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql:如何对列中字符的ASCII码求和?_Sql_Postgresql - Fatal编程技术网

Postgresql:如何对列中字符的ASCII码求和?

Postgresql:如何对列中字符的ASCII码求和?,sql,postgresql,Sql,Postgresql,设置示例: CREATE TABLE tbl (word TEXT); INSERT INTO tbl VALUES ('abc'); INSERT INTO tbl VALUES ('def'); 如何编写一个查询,返回每行的字中字符的ASCII码之和 例如,第一行应该是294('abc'变为97+98+99=294),第二行应该是303('def'变为100+101+102=303)。以下似乎有效: select word, (select sum(ascii(regexp

设置示例:

CREATE TABLE tbl (word TEXT);
INSERT INTO tbl VALUES ('abc');
INSERT INTO tbl VALUES ('def');
如何编写一个查询,返回每行的
中字符的ASCII码之和


例如,第一行应该是
294
('abc'变为97+98+99=294),第二行应该是
303
('def'变为100+101+102=303)。

以下似乎有效:

select
    word,
    (select sum(ascii(regexp_split_to_table)) from regexp_split_to_table(word, ''))
from tbl;

以下似乎有效:

select
    word,
    (select sum(ascii(regexp_split_to_table)) from regexp_split_to_table(word, ''))
from tbl;