[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Minimate partial upload fails
****** message to minivend-users from Mark Stosberg <mark@summersault.com> ******
> You have to have a key. I don't know how you are expecting the database to
> identify a record without one.
Thanks for the response Mike.
I'd like to show you an example of not using a key to identify a
record for an insert. This is a very handy way of letting Postgres
handle the auto numbering of the fields. I believe MySQL does something
similar with Auto_Increment.
[snip]
mcs=> create sequence t_seq;
mcs=> create table t (c1 int default nextval('t_seq'), c2 text);
mcs=> insert into t (c2) values ('test 1');
mcs=> insert into t (c2) values ('test two');
mcs=> select * from t;
c1|c2
--+--------
1|test 1
2|test two
(2 rows)
[/snip]
You'll notice that I didn't need to include a key in my inserts.
Postgres nicely creates them and numbers them for me. This would work
the same if "c1" was a primary key. This construct saves me an extra
select to manually get the next value in the sequence, and it makes it
much easier to create a mass insert file because I don't have to guess
what possible primary key values will be available the database.
If I'm creating an insert file offline while the database is live, the
sequence is likely to increment in the meantime, making it hard to guess
reasonable values!
Thanks,
-mark
<<-------------------------------------------------------------->>
personal website < Summersault Website Design
http://mark.stosberg.com/ > http://www.summersault.com/
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list