Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: numbering r...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 3448 of 3799
Post > Topic >>

Re: numbering rows on im****t from file

by scott.marlowe@[EMAIL PROTECTED] ("Scott Marlowe") May 2, 2008 at 05:00 PM

On Fri, May 2, 2008 at 3:26 PM, Alexy Khrabrov <deliverable@[EMAIL PROTECTED]
>
wrote:
> Greetings -- I have a huge table of the form
> (integer,integer,smallint,date).  Its origin is an ASCII file which I
load
> with \copy.  Now I want to number the rows, adding an id column as an
> autoincrement from a sequence.  How should I do the im****t now for the
> sequence to work -- should I add the id column last, so it will not be
> filled by copy and presumably autoincrement?

Add the sequence to the column.  something like this:

create table mytable (id serial primary key, int1 integer, int2
integer, smallint1 smallint, date1 date);
copy mytable (int1,int2, smallint1, date1) from STDIN;
120,2304,4,'2007-01-01'
204,3204,2,'2007-01-02'
(and so on)
\.

with a lot of other dbs, and a lot of languages, you're taught to
perform discrete steps when operating on your data.  Generally
speaking, PostgreSQL is much better at doing the most NOW, not later.
If you've got derived data you want to put into the table, put all the
data into a loading table, and transfer it to the real table with ONE
insert into select from query.

>  Or, once the table is already in, can I add a column and force it to be
> filled with consecutive numbers, effectively numbering the rows?

Bad idea.  As mentioned before, every update or insert, whether it
succeeds or not will create a dead row in the table.  If you update
(or attempt to update) all rows in a 10,000,000 row table three times,
you now have 30,000,000 dead rows in your table.

-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 4 Posts in Topic:
numbering rows on import from file
deliverable@[EMAIL PROTEC  2008-05-02 14:26:34 
Re: numbering rows on import from file
chestercyoung@[EMAIL PROT  2008-05-02 15:33:39 
Re: numbering rows on import from file
scott.marlowe@[EMAIL PROT  2008-05-02 17:00:33 
Re: numbering rows on import from file
scrawford@[EMAIL PROTECTE  2008-05-02 17:18:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 21:21:50 CST 2008.