小编Sun*_*her的帖子

从 Postgres 查询非 ASCII 行

[:ascii:]课堂在 Postgres 中是否有效?它没有列在他们的帮助中,但是我在网上看到使用它的例子

我有一个 UTF-8 数据库,其中collat​​ionc_typ e 是en_US.UTF-8,Postgres 版本是 9.6.2。当我像这样搜索非 ASCII 行时:

select title from wallabag_entry where title ~ '[^[:ascii:]]';
Run Code Online (Sandbox Code Playgroud)

我得到Unicode 和非 Unicode 符号(完整输出在这里):

?????????? ??????????????: ???? ????????? ??????? ?????
??????? ???????? ????????: ????? ?? ?????? ????????? ?? ???????
??? ?? ?????? ? ??????? ?? ????: ??? ? ????????????? ?????????? ???????????
??? ???????? ??????? ? 1740-? ???? ?? ??????? ??????? ??????
Have …
Run Code Online (Sandbox Code Playgroud)

postgresql regular-expression utf-8 regex unicode

17
推荐指数
1
解决办法
2万
查看次数

INSERT INTO table FROM SELECT * with nextval() 规范

我需要复制同一个表中的记录只更改一个字段。我的表有默认生成的序列entry_id_seq,但是我不确定id列是 SERIAL(如何检查?)。

\d tab 只返回这个

      Column      |              Type              |            Modifiers            
 -----------------+--------------------------------+------------------------
       id         |             integer            |            not null
...
Indexes:
"tab_entry_pkey" PRIMARY KEY, btree (id)
Run Code Online (Sandbox Code Playgroud)

所以问题是:当我尝试以简化的方式复制记录时:

insert into tab_entry select * from tab_entry where id = 3052;
Run Code Online (Sandbox Code Playgroud)

它抛出错误

ERROR:  duplicate key value violates unique constraint "tab_entry_pkey"
DETAIL:  Key (id)=(3052) already exists.
Run Code Online (Sandbox Code Playgroud)

默认情况下,默认序列不会生成下一个值。是否有任何简洁的语法允许在没有完整表规范的情况下插入和更改单个字段FROM tab(col1, col2, col3, ..., col N)

该表有很多字段,所以我不想把它们都写出来,因为这会影响代码的可读性。我想要这样的东西,但这种语法不起作用

insert into tab_entry(id, *) select nextval('seq'), * from tab_entry where id = 3052;
Run Code Online (Sandbox Code Playgroud)

SELECT …

postgresql primary-key insert sequence

5
推荐指数
1
解决办法
2万
查看次数