pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ignoring primary key violations in COPY command
4+ messages / 3 participants
[nested] [flat]

* ignoring primary key violations in COPY command
@ 2007-05-14 11:57 singh.srajendra@wipro.com
  0 siblings, 0 replies; 4+ messages in thread

From: singh.srajendra@wipro.com @ 2007-05-14 11:57 UTC (permalink / raw)
  To: pgsql-sql


Hi all, 
We are importing the data from the CSV file into the database using COPY
command. But when the 'primary key ' violation occurs , it stops 
Then and there and data is not updated into the tables. Also in the CSV
file the number of columns is not fixed , its varies 
In number , it can range anywhere between 1 -22, I need to figure out a
way such that I need to update only those columns which are present 
In the CSV file . This of course  I would like to accomplish using COPY
command , Please let me know if at all this is possible in postgresql
8.1

Thanks and regards,
Rajendra Singh
 
Wipro Technologies
Plot No. 72, Hosur Main road
Keonics Electronics City
Bangalore- 560100, INDIA
I believe we should all pay our tax with a smile. I tried - but they
wanted cash





The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* ignoring primary key violations in COPY command
@ 2007-05-14 12:36 singh.srajendra@wipro.com
  2007-05-19 22:29 ` Re: ignoring primary key violations in COPY command Paul Lambert <paul.lambert@autoledgers.com.au>
  0 siblings, 1 reply; 4+ messages in thread

From: singh.srajendra@wipro.com @ 2007-05-14 12:36 UTC (permalink / raw)
  To: pgsql-sql


Hi all, 

We are importing the data from the CSV file into the database using COPY
command. But when the 'primary key ' violation occurs , it stops 

Then and there and data is not updated into the tables. Also in the CSV
file the number of columns is not fixed , its varies 

In number , it can range anywhere between 1 -22, I need to figure out a
way such that I need to update only those columns which are present 

In the CSV file . This of course  I would like to accomplish using COPY
command , Please let me know if at all this is possible in postgresql
8.1

Thanks and regards,

Rajendra Singh

 

Wipro Technologies

Plot No. 72, Hosur Main road

Keonics Electronics City

Bangalore- 560100, INDIA

I believe we should all pay our tax with a smile. I tried - but they
wanted cash


The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.

www.wipro.com
	



The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: ignoring primary key violations in COPY command
  2007-05-14 12:36 ignoring primary key violations in COPY command singh.srajendra@wipro.com
@ 2007-05-19 22:29 ` Paul Lambert <paul.lambert@autoledgers.com.au>
  2007-05-19 23:58   ` Re: ignoring primary key violations in COPY command chester c young <chestercyoung@yahoo.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Paul Lambert @ 2007-05-19 22:29 UTC (permalink / raw)
  To: pgsql-sql

singh.srajendra@wipro.com wrote:
> Hi all,
> 
> We are importing the data from the CSV file into the database using COPY 
> command. But when the ‘primary key ‘ violation occurs , it stops
> 
> Then and there and data is not updated into the tables. Also in the CSV 
> file the number of columns is not fixed , its varies
> 
> In number , it can range anywhere between 1 -22, I need to figure out a 
> way such that I need to update only those columns which are present
> 
> In the CSV file . This of course  I would like to accomplish using COPY 
> command , Please let me know if at all this is possible in postgresql 8.1
> 
> /Thanks and regards,/
> 
> Rajendra Singh
> 

In my opinion your best bet in terms of getting around the primary key 
violation is to create a temporary table without a primary key, copy 
your data into that table, then do a select into your main table from 
that table.

Eg.. I do the following:

CREATE TABLE creditors_temp_load AS SELECT * FROM creditors WHERE 1=0;
TRUNCATE TABLE creditors;
COPY creditors_temp_load FROM 'c:/temp/autodrs_creditors.txt' WITH 
DELIMITER AS '^' QUOTE '\f' CSV HEADER;
INSERT INTO creditors (SELECT DISTINCT ON (dealer_id,supplier_no) * FROM 
creditors_temp_load WHERE (dealer_id,supplier_no) is not null);

The first statement creates a copy of the 'creditors' table without any 
records (none in the creditors table have 1 equal to zero)
The second copies the data from the file into the temp table.
Finally an insert into the 'creditors' table is done by a select 
distinct on the temp table where the two fields listed are the primary 
key for that table.

I don't believe there is any way of getting around not having all the 
fields present - copy expects to find a match between fields in the file 
and fields in the destination table. If your record length in the load 
file is going to vary you may need to consider writing a program to read 
the data from the file and load it in.

Regards,
Paul.

-- 
Paul Lambert
Database Administrator
AutoLedgers




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: ignoring primary key violations in COPY command
  2007-05-14 12:36 ignoring primary key violations in COPY command singh.srajendra@wipro.com
  2007-05-19 22:29 ` Re: ignoring primary key violations in COPY command Paul Lambert <paul.lambert@autoledgers.com.au>
@ 2007-05-19 23:58   ` chester c young <chestercyoung@yahoo.com>
  0 siblings, 0 replies; 4+ messages in thread

From: chester c young @ 2007-05-19 23:58 UTC (permalink / raw)
  To: Paul Lambert <paul.lambert@autoledgers.com.au>; +Cc: pgsql-sql


> In my opinion your best bet in terms of getting around the primary
> key 
> violation is to create a temporary table ...

good idea!  from my experience it's almost always best to pull raw info
into a buffer table before introducing it into the real world.


 
____________________________________________________________________________________
Bored stiff? Loosen up... 
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2007-05-19 23:58 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-05-14 11:57 ignoring primary key violations in COPY command singh.srajendra@wipro.com
2007-05-14 12:36 ignoring primary key violations in COPY command singh.srajendra@wipro.com
2007-05-19 22:29 ` Paul Lambert <paul.lambert@autoledgers.com.au>
2007-05-19 23:58   ` chester c young <chestercyoung@yahoo.com>

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