home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!caen!uwm.edu!rutgers!news.columbia.edu!usenet
- From: alan@curta.cc.columbia.edu (Alan Crosswell)
- Newsgroups: comp.databases.ingres
- Subject: Re: Silly question
- Message-ID: <1992Aug20.141936.26558@news.columbia.edu>
- Date: 20 Aug 92 14:19:36 GMT
- References: <16vmkoINNdoj@fulmar.doc.ic.ac.uk>
- Sender: usenet@news.columbia.edu (The Network News)
- Organization: Columbia University
- Lines: 51
- Nntp-Posting-Host: curta.cc.columbia.edu
-
- In article <16vmkoINNdoj@fulmar.doc.ic.ac.uk> rsoc@doc.ic.ac.uk (Rob
- O'Connor) writes:
- > Hi, as a relative novice user, I have a question. I have a column
- containing
- > a unique number, the next row being 1 more than the previous, i.e
- >
- > doc1
- > doc2
- > ..
- > ..
- > doc(n)
- > doc(n+1)
- > Is there a straightforward way to automatically update the next row as
- it's
- > added by looking back at the previous maximum value? So when I append a
- row,
- > Ingres looks back at the previous largest value and adds the next one by
- > default?
- > Apologies if it's a really stupid question, or I'm missing something
- obvious!
- > BTW system is version 6.3 on SunOS 4.1.1.
- >
- > Rob.
- > --
- > Internet: rsoc@doc.ic.ac.uk Tel: +44 71 589 5111 x5070 Fax: +44 71
- 581 8024
-
- Not, not silly and a big pain. If you are loading the table from a
- program, use a program variable to increment the number. For example:
-
- for (i = 0; xxx; i++) {
- ...
- exec sql insert into foo(docnum,blather) values(:i,:blather);
- }
-
- A cheap trick that I use sometimes which is a total violation of
- portability is to use the secret 'tid' (tuple-id) column on a heap
- storage-structure table. Heaps are just sequential, so I do stuff
- like:
-
- modify foo to truncated
- copy foo(blather) from '....'
- update foo set docnum=tid
-
- Then you can go ahead and modify foo to a different storage structure.
-
- There is also a system-maintained datatype (another non-portable but
- more acceptable feature of Ingres) where ingres explicitly manages the
- row number for you. See the SQL reference section of datatypes.
-
- /a
-