Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.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
Sql Postgres中的幽灵行_Sql_Postgresql_Duplicates - Fatal编程技术网

Sql Postgres中的幽灵行

Sql Postgres中的幽灵行,sql,postgresql,duplicates,Sql,Postgresql,Duplicates,在我打电话给幽灵杀手之前,我来这里是想试试技术哈哈 在我的Postgre数据库中有一个表,有284814条记录,我一直在寻找重复的记录,用这个表 select grupo, empresa, filial, unidade, diferenciadornumero, serie, numero, count(numero) from conhecimento group by grupo, empresa, filial, unidade, diferenciadornumero, seri

在我打电话给幽灵杀手之前,我来这里是想试试技术哈哈

在我的Postgre数据库中有一个表,有284814条记录,我一直在寻找重复的记录,用这个表

select grupo, empresa, filial, unidade, diferenciadornumero, serie, numero, count(numero) 
from conhecimento 
group by grupo, empresa, filial, unidade, diferenciadornumero, serie, numero 
having count(numero) > 1
它还给我五条记录:

1;1;9;1;2;9;24712;2
1;1;9;1;2;9;24708;2
1;1;9;1;2;9;24711;2
1;1;9;1;2;9;24713;2
1;1;9;1;2;9;24709;2
之后,我尝试一个接一个地查看这些记录,使用复合键带来记录,使用以下语句:

select grupo, empresa, filial, unidade, diferenciadornumero, serie,
       numero, ctid
from conhecimento 
where grupo = 1 and empresa = 1 and
      filial = 9 and unidade = 1 and diferenciadornumero = 2 and serie = 9 and 
      numero = 24712
让我惊讶的是,这个查询只返回一条记录

一,;1.9;1.2.9;24712;(7986,5)

现在我试图理解Postgre是如何告诉我这5条记录中有重复记录的,但当我试图从表中恢复这些记录时,只返回一行

我也已经使用了这个查询

select *
from (SELECT grupo, empresa, filial, unidade, diferenciadornumero, serie, numero, ctid,
             ROW_NUMBER() OVER (PARTITION BY grupo, empresa, filial, unidade,
                                             diferenciadornumero, serie, numero
                               ) AS Row
      FROM conhecimento
     ) dups
where  dups.Row > 1
但是如果没有运气,有人知道发生了什么

这是我的钥匙
grupo,empresa,孝顺,unidade,Diferenceiadornumero,serie,numero的组合。我的表是
conhecimento


我最诚挚的问候

这可能不是答案,但是

守则:

select *
from (SELECT grupo, empresa, filial, unidade, diferenciadornumero, serie, numero, ctid,
             ROW_NUMBER() OVER (PARTITION BY grupo, empresa, filial, unidade,
                                             diferenciadornumero, serie, numero
                               ) AS Row
      FROM conhecimento
     ) dups
where  dups.Row > 1
仅返回每个记录的第二个示例。实际上,您不需要
行数()
,而是需要
计数()


一种可能性是,一个或多个列是字符串,并且缺少前导或尾随空格。我在这里检查,所有列都是整数,是否可能在整数列中有尾随空格?!如果所有字段都是整数,那么示例输出的这一部分意味着什么<代码>;(7986,5)
它是一个字符串还是两个不同的整数?如果是两个不同的整数,那不是意味着两行不同吗?除非我遗漏了什么…@GordonLinoff我用这个语句来检查,它们的长度都是正确的:
select length(grupo::VARCHAR)、length(empresa::VARCHAR)、length(孝子::VARCHAR)、length(unidade::VARCHAR)、length(diferenceiadornumero::VARCHAR)、length(serie::VARCHAR)、length(numero::VARCHAR)、count(numero)来自grupo、empresa、Durth、unidade、diferenciadornumero、serie、numero的conhecimento group,计数(numero)>1;(7986,5)
值是表中的
CTID
,与Oracle数据库中的
ROWID类似,它不是键的一部分
select *
from (SELECT grupo, empresa, filial, unidade, diferenciadornumero, serie, numero, ctid,
             count(*) OVER (PARTITION BY grupo, empresa, filial, unidade,
                                         diferenciadornumero, serie, numero
                           ) AS cnt
      FROM conhecimento
     ) dups
where  dups.cnt > 1;