home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / database / informix / 1925 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  3.0 KB

  1. Path: sparky!uunet!wupost!emory!obelix.informix.com
  2. From: johnl@obelix.informix.com (Jonathan Leffler)
  3. Newsgroups: comp.databases.informix
  4. Subject: Re: HELP! Trying to UPDATE temp table HELP!
  5. Message-ID: <9528@emory.mathcs.emory.edu>
  6. Date: 14 Sep 92 12:23:07 GMT
  7. Sender: walt@mathcs.emory.edu
  8. Reply-To: johnl@obelix.informix.com (Jonathan Leffler)
  9. Lines: 59
  10. X-Informix-List-ID: <list.1444>
  11.  
  12. >From: Dave Snyder <uunet!widener!das13!dave.snyder>
  13. >Subject: Re: HELP! Trying to UPDATE temp table HELP!
  14. >Date: Mon, 7 Sep 92 14:27:56 EDT
  15. >X-Informix-List-Id: <list.1432>
  16. >
  17. >Quoting Mark L Trotter...
  18. >}
  19. >}    I am trying to create a temporary table, insert some elements from
  20. >} another table, then go thru the temporary table using a cursor and
  21. >} do some updating of other elements.  All works except:
  22. >}    1. I can't DEFINE a memory record LIKE the temporary table because
  23. >}       it doesn't exist at compile time so I assume I must define the
  24. >}       entire memory record via listing all of the elements, but if I do
  25. >}       that then:
  26. >}    2. I can't UPDATE the temporary table using
  27. >}        UPDATE temptablename SET temptablename.* = memrecord.*
  28. >}       because I get a compile error saying that memrecord was not
  29. >}       defined using the RECORD LIKE phrase.
  30. >} Is this a know bug and is there any workarounds?
  31.  
  32. No, it is not a bug but it is a known pair of restrictions.
  33.  
  34. >Try this:
  35. >DEFINE the record the "long hand" way and then use an UPDATE statement like
  36. >this one...
  37. >
  38. >UPDATE temptablename SET (temptablename.col1, temptablename.col2, etc...)
  39. >               = (memrecord.col1, memrecord.col2, etc...)
  40.  
  41. As an alternative, define a view which (a) contains no rows, and (b)
  42. contains the required column types, and compile against that view.
  43.  
  44. This may not work with temporary tables, but I do use the technique for
  45. input where I need data from a number of different tables.  The sort
  46. of view I have in mind is:
  47.  
  48. CREATE VIEW Compiler_view_001 (ColumnA, ColumnB, ...) AS
  49.     SELECT A.Column1, B.Column2, ...
  50.         FROM TableA A, TableB B, ...
  51.         WHERE 1 = 0;
  52.  
  53. The other alternative is to create a permanent table with the required
  54. columns and use that instead of the temporary table.  This is often not
  55. satisfactory in a multi-user environment, but sometimes it can work.
  56. I have a batch program that grabs the database in exclusive mode and
  57. uses a permanent table as an intermediate results file; when the program
  58. completes, it drops the table and rebuilds it.  The program is run once
  59. a week in the wee small hours (about 04:00) and this works quite nicely
  60. in this case, thank you.  It may not be relevant for your problem -- sorry.
  61.  
  62. Finally, you could try preparing the UPDATE statement and execute it
  63. with a USING clause listing all the elements in the record.  You will need
  64. to worry about supplying the values for the WHERE clause as well as the SET
  65. clause.  If you prepare it just once, your performance will also improve
  66. (provided you execute it more than once), though the difference may not
  67. be easily measurable.
  68.  
  69. Yours,
  70. Jonathan Leffler (johnl@obelix.informix.com) #include <disclaimer.h>
  71.