Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fuO9u-0005GH-Iq for pgsql-general@arkaria.postgresql.org; Mon, 27 Aug 2018 20:30:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fuO9r-0007CN-Vs for pgsql-general@arkaria.postgresql.org; Mon, 27 Aug 2018 20:30:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fuO9r-0007CG-MB for pgsql-general@lists.postgresql.org; Mon, 27 Aug 2018 20:30:43 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fuO9n-0004jc-8V for pgsql-general@postgresql.org; Mon, 27 Aug 2018 20:30:42 +0000 Received: by mail-pl1-x644.google.com with SMTP id ba4-v6so93218plb.11 for ; Mon, 27 Aug 2018 13:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=RUFEYlAHCvEAJFPuv539ZGexC+wGnR7xpvlukloql7I=; b=TAPHjNcgpE3EDbT16xhm3isei1f40ouK33YdW2zu2YHiKvPBQmK5zC8iNTPMzMFGEp Qqv74xUh7s9Ida+uyAJVT1wXFEPcFEvc218xaa57DXJkuKmL1xZREPAyGHWx2yxJfK/G 6KsFVZyrPxEb+RFejU0qNMVnKCs897r0SwayE/5TaC3yxKryRw3Qbu1sGQWpB1bnvsIQ LqnUYd9DFeVlm+7Z5ae7Qz981XS2rqB/iElL3BXIlwYO9YD9Pp1Cvo9BKh7F2WomGsRs ubEoCMMACWYWu8knekYcIZRcvHdheQ+kjaRoAssO2Mbz9hnEmSCEoyFzGGJhFOjM2Mdw s14g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=RUFEYlAHCvEAJFPuv539ZGexC+wGnR7xpvlukloql7I=; b=i2th0fvxjpPGRrSPymWuDtKoR3c6wx1W6bh+vKJMRq+lrIoLHiJsTmeGVyduTP0hUw 74Q4ikJu2+t5RXjOPhXLfRyosbuRj7lZdqK37P6Kui0dJEPDrupx+lO+aqgag4wgXln0 /WQ3s24AN51BcmLCyNGaLI0YZTeMZfYRuFI3XBz4tnMLeoOuZEOICcPgie1xDKmyw2Sw ClAn7kXxrD6nenTBixf0UlmD/Ckjx4XFyPQgiq6uHlh/ojDXlZzeA+8g3bmqXBAC5xxq FZHAlplzZCG5a/8Bs7XdJAKJp1rix5GMlN9vhVk/6W6kQN3e+gVsRpXHkyurG51gXTVo 4P8Q== X-Gm-Message-State: APzg51CtY1bsseu5goJiu99Ons3VzrTdx0Kbx8JnMJl8z7LlF7yW84Rb kYdJqLVkKwt0KPWQ+ih97g8VBWGY X-Google-Smtp-Source: ANB0VdboxsvIcVRyP6VOZC/i9Dx8w7LP7wuf3gvAKh4hd65/fky/IKRGdYsjDDsJHgsgt7L+ZIgPcA== X-Received: by 2002:a17:902:27e6:: with SMTP id i35-v6mr14529387plg.187.1535401836399; Mon, 27 Aug 2018 13:30:36 -0700 (PDT) Received: from ?IPv6:2600:100e:b11d:b764:bd4d:2ef4:6c55:7081? ([2600:100e:b11d:b764:bd4d:2ef4:6c55:7081]) by smtp.gmail.com with ESMTPSA id v24-v6sm167328pfl.31.2018.08.27.13.30.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Aug 2018 13:30:35 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (1.0) Subject: Re: Erroneous behavior of primary key From: Rob Sargent X-Mailer: iPhone Mail (15G77) In-Reply-To: Date: Mon, 27 Aug 2018 14:30:34 -0600 Cc: pgsql-general@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <1B74B41D-936B-464D-9D53-A7374C27F3A2@gmail.com> References: To: Daniel J Peacock List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Aug 27, 2018, at 1:50 PM, Daniel J Peacock wrot= e: >=20 > Good afternoon, all. > I've got an odd situation with a table that has a varchar(255) as the prim= ary key that is getting key values from an Elasticsearch engine. What I'm f= inding is that even though there is a primary key on the table, I am getting= duplicated keys in the data and the constraint is not blocking these. When= I do a "select ,count(*) from group by having c= ount(*) > 1" I get no results. Yet, when I search the table for a value tha= t is like a key I know to be duplicated, I get multiple results. When I sel= ect from the table where field is equal to the duplicated field I get one re= sult. I verified that they are distinct row with ctid. I also created a cl= one of the table with CTAS and then tried to create a unique index on the id= varchar field but that failed with "duplicate keys found". I'm stumped as t= o what could be the problem. > The only thing that I can think of is that the primary key is somehow corr= upt. I've noticed this behavior on other tables on this database. =20 > What could be causing this sort of problem? >=20 > Thanks in advance for any insights. >=20 > Dan Peacock > Auto-wares, Inc. Check for trailing white space=