pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Holger Jakobs <holger@jakobs.com>
To: pgsql-admin@lists.postgresql.org,Rui DeSousa <rui@crazybean.net>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: soumik.bhattacharjee@kpn.com,pgsql-admin <pgsql-admin@postgresql.org>
Cc: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: Composite primary key duplicate records - Issue In PostgreSQL But not in Oracle
Date: Wed, 22 Apr 2020 16:18:46 +0200
Message-ID: <256CA957-E271-4EBB-98FF-1B337AFD9F17@jakobs.com> (raw)
In-Reply-To: <671E1525-61C8-4A7B-AB1F-F936BF22ED49@crazybean.net>
References: <2A91BEF8171A5349931391E0C721CC5396920741@CPEMS-KPN301.KPNCNL.LOCAL>
	<CAKFQuwZwF8eUAxnxzvFWBQpeWwBDMew1Dhtu7rX=KcHM9S92MA@mail.gmail.com>
	<671E1525-61C8-4A7B-AB1F-F936BF22ED49@crazybean.net>

Oracle DATE is actually a TIMESTAMP(0) 


Am 22. April 2020 16:16:07 MESZ schrieb Rui DeSousa <rui@crazybean.net>:
>
>
>> On Apr 22, 2020, at 10:09 AM, David G. Johnston
><david.g.johnston@gmail.com> wrote:
>> 
>> On Wed, Apr 22, 2020 at 6:54 AM <soumik.bhattacharjee@kpn.com
><mailto:soumik.bhattacharjee@kpn.com>> wrote:
>> Hi Experts,
>> 
>>  
>> 
>> We are migrating Oracle to PostgreSQL and facing a challenge related
>to constrains.
>> 
>>  
>> 
>> In Oracle database there are lot of table consists of composite
>primary key which having duplicate records.
>> 
>>  
>> 
>> Example
>> 
>>  
>> 
>> Oracle  table : --CONSTRAINT "TTT_PRX" PRIMARY KEY ("COL1", "COL2") –
>UNIQUE à Here in Oracle there is no issue
>>  
>> 
>> In PostgreSQL if I want to add the constraint post migration it
>throws error as duplicate record for COL1 (which is a number) as per
>business need, COL2 is date which is unique always.
>>  
>> 
>> alter table table_name add constraint ttt_prx unique(COL1, COL2);
>> 
>>  
>> 
>> COL1
>> 
>> COL2
>> 
>> Count
>> 
>> 102022194
>> 
>> 21-9-2019
>> 
>> 1
>> 
>> 102022194
>> 
>> 30-9-2019
>> 
>> 1
>> 
>> 102022194
>> 
>> 30-9-2019
>> 
>> 1
>> 
>>  
>> 
>>  
>> 
>> Is there a way to handle this in PostgreSQL?
>> 
>> 
>> 
>> 
>> If Oracle is telling you that having two records
>(102022194,30-9-2019) is not a violation of the defined unique
>constraint over those two columns it is wrong.  PostgreSQL is handling
>this correctly.
>> 
>> Maybe you had a full-on timestamp in Oracle but in moving it to
>PostgreSQL you mis-typed it as a date so the difference in the time
>portion of the two records has been lost?
>> 
>> David J.
>
>Correct, the issue is the data in Oracle.  The date field internally
>stores down to the second; not a great idea to use date in as primary
>key on Oracle without truncating it first:
>
>https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:47566188181366

-- 
Holger Jakobs, Bergisch Gladbach
+49 178 9759012
- sent from mobile, therefore short -

view thread (5+ messages)  latest in thread

Message-ID: <256CA957-E271-4EBB-98FF-1B337AFD9F17@jakobs.com>
Permalink:  ../256CA957-E271-4EBB-98FF-1B337AFD9F17@jakobs.com/
Also on:    postgresql.org/message-id/256CA957-E271-4EBB-98FF-1B337AFD9F17@jakobs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: holger@jakobs.com, rui@crazybean.net, david.g.johnston@gmail.com
  Subject: Re: Composite primary key duplicate records - Issue In PostgreSQL But not in Oracle
  In-Reply-To: <256CA957-E271-4EBB-98FF-1B337AFD9F17@jakobs.com>
  References: <2A91BEF8171A5349931391E0C721CC5396920741@CPEMS-KPN301.KPNCNL.LOCAL> <CAKFQuwZwF8eUAxnxzvFWBQpeWwBDMew1Dhtu7rX=KcHM9S92MA@mail.gmail.com> <671E1525-61C8-4A7B-AB1F-F936BF22ED49@crazybean.net> <256CA957-E271-4EBB-98FF-1B337AFD9F17@jakobs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox