db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: javaDB IDENTITY column and INSERTS
Date Tue, 18 May 2010 07:15:06 GMT
On 05/16/10 12:11 PM, Myraddin wrote:
> 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:
>
>
> 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:
>
>
> 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:
>
> 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 ?
>

Hi,

You could specify a subset of the columns, like this:

INSERT INTO DIRECTION (SOURCE_AREA_ID)
   SELECT AREA_ID FROM FOOBAR_AREA


Hope this helps,

-- 
Knut Anders


Mime
View raw message