gpt4 book ai didi

postgresql - Postgres 更改数字格式

转载 作者:行者123 更新时间:2023-11-29 13:47:28 25 4
gpt4 key购买 nike

在 Postgres 中我使用这个查询:

UPDATE managers SET phone_number = replace(phone_number, '\m86', '3706');

不幸的是字段太长,查询失败。我需要将所有以 86 开头的数字更改为以 3706 开头...

我尝试了很多 Postgres 的功能,但它们是否具有我需要的功能并不明显。

错误是:

ERROR:  function replace(bigint, unknown, unknown) does not exist
LINE 1: UPDATE managers SET phone_number = replace(phone_number, '\m...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.

表定义:

CREATE TABLE public.managers(
phone_number bigint,
email_report boolean,
)

最佳答案

正如评论中所指出的那样,如果您使用正则表达式替换,就可以更轻松地阐明以 86 开头的数字是什么。其模式只是 ^86,替换为 3706。考虑以下查询:

UPDATE managers
SET phone_number = REGEXP_REPLACE(phone_number::text, '^86', '3706')::int

关于postgresql - Postgres 更改数字格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46068057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com