INSERT INTO table without specifying columns

168 views
Skip to first unread message

Max Kremer

unread,
Oct 9, 2015, 3:58:27 PM10/9/15
to jOOQ User Group
Hello 

  I'm trying to insert into a table without specifying table's columns names which perfectly valid SQL:

INSERT INTO FOO VALUES ('A', 'B', 500)

The above will execute without error when the values line up with the columns in the table.

How can I accomplish the above with JOOQ? My attempt below doesnt compile to a cryptic generic error

InsertValuesStepN<Record> sql = dsl.insertInto(dsl.table("foo"));

for (...){
   
   
List<Field<?>> values = Lists.newArrayList();      

   
for ( ... ) {
     values
.add(val("someval", type));
   
}
   
   sql
= sql.values(values);
}

sql
.execute();




Lukas Eder

unread,
Oct 12, 2015, 12:06:15 PM10/12/15
to jooq...@googlegroups.com
Hello Max,

You can write an INSERT statement without specifying the target columns with jOOQ, although, jOOQ will try to take those from the table supplied via Table.fields().

I've just noticed that this doesn't work at all with plain SQL tables. I've registered an issue for this:

In the meantime, you'll have to specify the column names, I'm afraid...

Best Regards,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages