Results 1 to 4 of 4
  1. #1
    myraddin is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Unhappy javaDB IDENTITY column and INSERTS

    Hi all.
    My first post so bare with me if I have chosen the wrong place to ask.

    I created a table in JavaDB like this:

    Java Code:
    CREATE TABLE DIRECTION(
      DIRECTION_ID INT PRIMARY KEY NOT NULL GENERATED DEFAULT AS IDENTITY, 
      SOURCE_AREA_ID      INT NOT NULL
    );
    (it's a bit shortened but will prove my point.

    Now I would like to throw in some data by using INSERT with a SELECT query like this:

    Java Code:
    INSERT INTO DIRECTION 
       SELECT AREA_ID
        FROM FOOBAR_AREA;
    The error thrown is (as expected): The number of values assigned is not the same as the number of specified or implied columns.

    Then I try:
    Java Code:
    INSERT INTO DIRECTION 
       SELECT {auto|default|xxx?},AREA_ID
        FROM FOOBAR_AREA;
    and nothing helps.

    How DOES one do an INSERT using select query into a table with an auto-generated identity column ?

    Thanks !

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    First wellcome :)

    I am afraid it is not Java question but SQL one :(

    Anyway... If your table contains X columns you have to INSERT X params. Either they would be null or not it doesn't matter...
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  3. #3
    myraddin is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Smile

    Thank you Webuser.

    I saw a few posts about JavaDB on these forums so ... i thought...

    Never mind then.

    As for you reply it's not actually related to my question but thank you for trying ;)

    Happy coding.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Have you tried simply
    Java Code:
    INSERT INTO DIRECTION (SOURCE_AREA_ID)
       SELECT AREA_ID
        FROM FOOBAR_AREA;
    Seeing as how when you only give it one value when the table has two columns, the DB is not going to take responsibility for the action (and consequences) and attempt to "guess" at which column should be getting the value provided.

Similar Threads

  1. insert row and column and delete row and column
    By daredavil82 in forum New To Java
    Replies: 13
    Last Post: 09-22-2011, 07:10 PM
  2. IBM Tivoli Identity Manager
    By pooja_k in forum Jobs Offered
    Replies: 0
    Last Post: 01-11-2010, 07:29 AM
  3. JavaDB Help
    By Sysem in forum New To Java
    Replies: 5
    Last Post: 05-29-2008, 10:21 PM
  4. JavaDB Installation
    By PhilArmstrong in forum New To Java
    Replies: 6
    Last Post: 05-13-2008, 03:09 PM
  5. how to count 2 inserts together?
    By kim85 in forum New To Java
    Replies: 0
    Last Post: 01-20-2008, 12:25 PM

Tags for this Thread

Posting Permissions

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