home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / database / ingres / 1185 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  2.0 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!caen!uwm.edu!rutgers!news.columbia.edu!usenet
  2. From: alan@curta.cc.columbia.edu (Alan Crosswell)
  3. Newsgroups: comp.databases.ingres
  4. Subject: Re: Silly question
  5. Message-ID: <1992Aug20.141936.26558@news.columbia.edu>
  6. Date: 20 Aug 92 14:19:36 GMT
  7. References: <16vmkoINNdoj@fulmar.doc.ic.ac.uk>
  8. Sender: usenet@news.columbia.edu (The Network News)
  9. Organization: Columbia University
  10. Lines: 51
  11. Nntp-Posting-Host: curta.cc.columbia.edu
  12.  
  13. In article <16vmkoINNdoj@fulmar.doc.ic.ac.uk> rsoc@doc.ic.ac.uk (Rob  
  14. O'Connor) writes:
  15. > Hi, as a relative novice user, I have a question. I have a column  
  16. containing
  17. > a unique number, the next row being 1 more than the previous, i.e
  18. > doc1
  19. > doc2
  20. > ..
  21. > ..
  22. > doc(n)
  23. > doc(n+1)
  24. > Is there a straightforward way to automatically update the next row as  
  25. it's
  26. > added by looking back at the previous maximum value? So when I append a  
  27. row,
  28. > Ingres looks back at the previous largest value and adds the next one by
  29. > default?
  30. > Apologies if it's a really stupid question, or I'm missing something  
  31. obvious!
  32. > BTW system is version 6.3 on SunOS 4.1.1.
  33. > Rob.
  34. > -- 
  35. > Internet: rsoc@doc.ic.ac.uk   Tel: +44 71 589 5111 x5070   Fax: +44 71  
  36. 581 8024
  37.  
  38. Not, not silly and a big pain.  If you are loading the table from a
  39. program, use a program variable to increment the number.  For example:
  40.  
  41.    for (i = 0; xxx; i++) {
  42.       ...
  43.       exec sql insert into foo(docnum,blather) values(:i,:blather);
  44.    }
  45.  
  46. A cheap trick that I use sometimes which is a total violation of
  47. portability is to use the secret 'tid' (tuple-id) column on a heap
  48. storage-structure table.  Heaps are just sequential, so I do stuff
  49. like:
  50.  
  51.   modify foo to truncated
  52.   copy foo(blather) from '....'
  53.   update foo set docnum=tid
  54.  
  55. Then you can go ahead and modify foo to a different storage structure.
  56.  
  57. There is also a system-maintained datatype (another non-portable but
  58. more acceptable feature of Ingres) where ingres explicitly manages the
  59. row number for you.  See the SQL reference section of datatypes.
  60.  
  61. /a
  62.