From: | "drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com> |
---|---|
To: | James Keener <jim(at)jimkeener(dot)com> |
Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Unique UUID value - PostgreSQL 9.2 |
Date: | 2016-03-14 22:44:08 |
Message-ID: | CAE_gQfU98v=9t9MnzX6=2K1LkVZndMRVPmXG0AAp1bPT3Q42tw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>
>
>
> On the target table, I've got a CONSTRAINT:
>
>> ALTER TABLE dm.billables
>> ADD CONSTRAINT uc_billable_code_unique_per_account UNIQUE("account_id",
>> "code");
>
>
> So I'm importing a CSV file with repeated values on the field "code"
> Example:
>
>> 'Interpreting Normal/AH'
>> 'Interpreting Normal/AH'
>> 'Interpreting Normal/AH'
>> 'Interpreting Normal/AH'
>> 'Interpreting Normal/AH4'
>> 'Interpreting Normal/AH'
>> 'Interpreting Normal/AH6'
>> 'Interpreting Normal/AH'
>
>
> So when importing it to the target table I got the error:
>
>> ERROR: duplicate key value violates unique constraint
>> "uc_billable_code_unique_per_account"
>> DETAIL: Key ("account_id", "code")=(32152, 'Interpreting Normal/AH')
>> already exists.
>
> Command used to import the values:
>
>> INSERT INTO dm.billables (SELECT billable_id, code, info FROM temptable)
>
> OR directly through the CSV file:
>
> COPY dm.billables (code, info, unit_cost, unit_price, account_id) FROM
>> '/var/lib/pgsql/sql/lucas/charge_test.csv' WITH DELIMITER ',' QUOTE '"' CSV
>> HEADER;
>
>
> So. I determined that to do that without dropping the CONSTRAINT, I'll
> have to generate a unique but random value to the "code" column.
>
> *NOW:*
> *COLUMN CODE | COLUMN INFO*
> 'Interpreting Normal/AH' Travel1
> 'Interpreting Normal/AH1' trip2
> 'Interpreting Normal/AH2' test897
> 'Interpreting Normal/AH3' trip11
> 'Interpreting Normal/AH4' trave1
>
> *NEW:*
> *COLUMN CODE | COLUMN INFO*
> code_32152563bdc6453645 Travel1
> code_32152563bdc4566hhh trip2
> code_32152563b654645uuu test897
> code_32152563bdc4546uui trip11
> code_32152563bdc4db11aa trave1
>
> How can I do that?
>
I could also drop the COSNSTRAINT, import all the data and then change the
"code" column to use UUID - *But how?*
From | Date | Subject | |
---|---|---|---|
Next Message | Brent Wood | 2016-03-14 22:44:46 | Re: Unique UUID value - PostgreSQL 9.2 |
Previous Message | Michael Paquier | 2016-03-14 22:20:12 | Re: how to switch old replication Master to new Standby after promoting old Standby |