Ask a Question related to Informix, Design and Development.

  1. #1

    Default Insert from Select


    I'm trying to insert from a select statement but it is giving me an error
    that I "Cannot modify table or view used in subquery." on my where clause.
    Why?

    INSERT INTO hospcontact
    (hospital_id, name, sir_name, first_name, nick_name, use_nick_name, title,
    street, street2,
    city, state, zip, bl, bl_is_prim, stmt, stmt_is_prim, day, day_is_prim,
    pcsr, pcsr_is_prim, special, special_is_prim,
    ub92, ub92_is_prim, pl, pl_is_prim, agedbl, patient_acct_mgr,
    last_modified, phone, fax, modified_by, email)

    Select 500368, name, sir_name, first_name, nick_name, use_nick_name, title,
    street, street2,
    city, state, zip, bl, bl_is_prim, stmt, stmt_is_prim, day, day_is_prim,
    pcsr, pcsr_is_prim, special, special_is_prim,
    ub92, ub92_is_prim, pl, pl_is_prim, agedbl, patient_acct_mgr, last_modified,
    phone, fax, modified_by, email
    from hospcontact
    where hospital_id=500349;
    sending to informix-list
    RPhillips@ce-a.com Guest

  2. Similar Questions and Discussions

    1. insert into...select using the same table
      How can I do the following in MySQL. insert into table1 (col1, col2, col3) select col1, col2, somevalue as col3 from table1 MySQL doesn't...
    2. What's faster - loop for insert or insert...select.
      What is faster if I'm moving large numbers of records (anywhere from 10,000 to 300,000 records per archive) from one query to another table? 1)...
    3. SELECT and INSERT
      Is there a way to do the SELECT and INSERT in a single SQL statement in MS-Access?
    4. How to select and then loop while insert
      I need help in writing a stored procedure on SQL Server 2000. Basically the stored procedure's primary task is to generate invoice records and...
    5. cursor with insert/select
      I have a cursor that inserts rows in a table. Simple enough stuff, but I'm a little confused by something that's happening. Instead of the sproc...
  3. #2

    Default Re: Insert from Select

    On Mon, 28 Jul 2003 16:26:48 -0400, "Art S. Kagel"
    <kagel@bloomberg.net> wrote:
    >On Mon, 28 Jul 2003 14:45:41 -0400, RPhillips wrote:
    >
    >Version and platform?? The problem was a race condition sort-of-thing.
    >If you are inserting using a select from the same table you could get
    >into an infinite loop internally where each new row becomes part of the
    >select. I think this was solved in 9.30 and is now permitted??
    >
    No problems (apparently) in 9.30.
    John Carlson Guest

  4. #3

    Default Re: Insert from Select

    [email]RPhillips@ce-a.com[/email] wrote:
    > I'm trying to insert from a select statement but it is giving me an error
    > that I "Cannot modify table or view used in subquery." on my where clause.
    > Why?
    Because you have not upgraded to a sufficiently recent version of the
    server. For a very long time, it was not possible to insert into
    TableA if TableA was also mentioned in the SELECT statement.
    Fortunately, that limitation has been removed in later versions.
    > INSERT INTO hospcontact
    > (hospital_id, name, sir_name, first_name, nick_name, use_nick_name, title,
    > street, street2,
    > city, state, zip, bl, bl_is_prim, stmt, stmt_is_prim, day, day_is_prim,
    > pcsr, pcsr_is_prim, special, special_is_prim,
    > ub92, ub92_is_prim, pl, pl_is_prim, agedbl, patient_acct_mgr,
    > last_modified, phone, fax, modified_by, email)
    >
    > Select 500368, name, sir_name, first_name, nick_name, use_nick_name, title,
    > street, street2,
    > city, state, zip, bl, bl_is_prim, stmt, stmt_is_prim, day, day_is_prim,
    > pcsr, pcsr_is_prim, special, special_is_prim,
    > ub92, ub92_is_prim, pl, pl_is_prim, agedbl, patient_acct_mgr, last_modified,
    > phone, fax, modified_by, email
    > from hospcontact
    > where hospital_id=500349;


    --
    Jonathan Leffler #include <disclaimer.h>
    Email: [email]jleffler@earthlink.net[/email], [email]jleffler@us.ibm.com[/email]
    Guardian of DBD::Informix v2003.04 -- [url]http://dbi.perl.org/[/url]

    Jonathan Leffler Guest

  5. #4

    Default Re: Insert from Select

    Jonathan Leffler <jleffler@earthlink.net> wrote in message news:<3F261374.9060502@earthlink.net>...
    > [email]RPhillips@ce-a.com[/email] wrote:
    >
    > Because you have not upgraded to a sufficiently recent version of the
    > server. For a very long time, it was not possible to insert into
    > TableA if TableA was also mentioned in the SELECT statement.
    > Fortunately, that limitation has been removed in later versions.
    >
    I have been getting error -360 on 9.3. In what version was it fixed?
    Kristofer Andersson Guest

  6. #5

    Default Re: Insert from Select

    On 29 Jul 2003 07:03:53 -0700, [email]anderssonk75@hotmail.com[/email] (Kristofer
    Andersson) wrote:
    >Jonathan Leffler <jleffler@earthlink.net> wrote in message news:<3F261374.9060502@earthlink.net>...
    >> [email]RPhillips@ce-a.com[/email] wrote:
    >>
    >> Because you have not upgraded to a sufficiently recent version of the
    >> server. For a very long time, it was not possible to insert into
    >> TableA if TableA was also mentioned in the SELECT statement.
    >> Fortunately, that limitation has been removed in later versions.
    >>
    >
    >I have been getting error -360 on 9.3. In what version was it fixed?
    We're on 9.30.HC3 . . . no problems. Is this a table or a view??
    John Carlson Guest

  7. #6

    Default Re: Insert from Select

    John Carlson <john_carlson@whsmithusa.com> wrote in message news:<3e1divsi7b4vanoh7955bc7jcl4j72pmlv@4ax.com>. ..
    >
    > We're on 9.30.HC3 . . . no problems. Is this a table or a view??
    >
    Table. But looking back at it, it was not an insert but an update. So
    maybe it has been fixed for insert but not for update...?
    Kristofer Andersson Guest

  8. #7

    Default Re: Insert from Select



    CREATE TEMP TABLE t(i INTEGER NOT NULL);
    INSERT INTO t VALUES(10);
    INSERT INTO t SELECT i + 10 FROM t;

    -- Ok until here :

    -- Trying to set all columns to 0
    UPDATE t SET i = i - (SELECT i from t tx WHERE tx.i = t.i);

    360: Cannot modify table or view used in subquery.

    .... So ...

    it works for INSERTs but not forUPDATEs...

    that's some advance,


    Jean Sagi.



    Kristofer Andersson wrote:
    > John Carlson <john_carlson@whsmithusa.com> wrote in message news:<3e1divsi7b4vanoh7955bc7jcl4j72pmlv@4ax.com>. ..
    >
    >>We're on 9.30.HC3 . . . no problems. Is this a table or a view??
    >>
    >
    >
    > Table. But looking back at it, it was not an insert but an update. So
    > maybe it has been fixed for insert but not for update...?
    >
    >

    --


    Atte,


    Jesús Antonio Santos Giraldo
    [email]jeansagi@myrealbox.com[/email]
    [email]jeansagi@netscape.net[/email]


    sending to informix-list
    Jean Sagi Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139