To make matters more interesting, I tried using DSL.name():

CreateTableConstraintStep step2 = createTable(table(name("Supplier")))
.column(field(name("SNUM"), INTEGER))
.column(field(name("SNAME"), VARCHAR(16).nullable(false)))
.column(field(name("STATUS"), INTEGER.nullable(false)))
.column(field(name("CITY"), VARCHAR(20).nullable(false)))
.constraints(primaryKey(field(name("SNUM"))),
unique(field(name("SNAME"))));

System.out.println(step2.toString());
String sql2 = step2.getSQL();
System.out.println(sql2);
System.out.println();

This results in quoted identifies, like in my first example:

create table "Supplier" (
  "SNUM" integer null,
  "SNAME" varchar(16) not null,
  "STATUS" integer not null,
  "CITY" varchar(20) not null,
  primary key ("SNUM"),
  unique ("SNAME")
)
create table "Supplier" ("SNUM" integer null, "SNAME" varchar(16) not null, 
"STATUS" integer not null, "CITY" varchar(20) not null, primary key 
("SNUM"), unique ("SNAME"))

Thus, this approach:

CreateTableConstraintStep step1 = createTable(table("Supplier"))
.column(field("SNUM", INTEGER))
.column(field("SNAME", VARCHAR(16).nullable(false)))
.column(field("STATUS", INTEGER.nullable(false)))
.column(field("CITY", VARCHAR(20).nullable(false)))
.constraints(primaryKey(field("SNUM")),
unique(field("SNAME")));

Appears to be using the quoted string values as direct SQL and they are 
thus not being rendered through JOOQ's assumed default quoting mechanism. 
That isn't what I expected to happen, but it seems like that is what is 
going on.
On Friday, July 30, 2021 at 3:27:45 PM UTC-5 Manuel Rossetti wrote:

> The code that I showed was based entirely on the DSL class, which does not 
> require the specification of the SQL dialect.   With that said, I am using 
> Apache Derby.  
>
> I found the issue after creating the table using the first syntax option:
>
> CreateTableConstraintStep step = createTable("Supplier")
> .column("SNUM", INTEGER)
> .column("SNAME", VARCHAR(16).nullable(false))
> .column("STATUS", INTEGER.nullable(false))
> .column("CITY", VARCHAR(20).nullable(false))
> .constraints(
> primaryKey("SNUM"),
> unique("SNAME"));
>
> And then trying to execute an insertInto() statement:
>
> myDSL.insertInto(table("Supplier"), field("SNUM"), field("SNAME"), 
> field("STATUS"), 
> field("CITY"))
> .values(1, "Smith", 20, "London")
> .values(2, "Jones", 10, "Paris")
> .values(3, "Blake", 30, "Paris")
> .values(4, "Clark", 20, "London")
> .values(5, "Adams", 30, "Athens").execute();
>
> The insertInto() does not have the option of allowing String specification 
> of the table and fields. Thus, I had to use the 
> table() and field() methods of the DSL.  The insert statement is rendered 
> without quotes and the create table statement was
> rendered with quotes.  Thus, the table and field names are not found.
> On Friday, July 30, 2021 at 3:04:40 PM UTC-5 [email protected] wrote:
>
>>
>> On Jul 30, 2021, at 1:53 PM, Manuel Rossetti <[email protected]> wrote:
>>
>> Hello, 
>> I am using JOOQ to make a tutorial for my students.  I see the following 
>> rendering behavior:
>> import static org.jooq.impl.DSL.*; // this import allows for the fluent 
>> use of the DSL class
>> import static org.jooq.impl.SQLDataType.*; // this import is so that you 
>> don't have to type SQLDataType.INTEGER etc
>>
>> // this statement builds a step in a SQL build process that defines a 
>> table creation
>> CreateTableConstraintStep step = createTable("Supplier")
>> .column("SNUM", INTEGER)
>> .column("SNAME", VARCHAR(16).nullable(false))
>> .column("STATUS", INTEGER.nullable(false))
>> .column("CITY", VARCHAR(20).nullable(false))
>> .constraints(
>> primaryKey("SNUM"),
>> unique("SNAME"));
>> // the statement can be printed, etc. But, more usefully it can be 
>> executed within a context.
>> System.out.println(step.toString());
>> String sql = step.getSQL();
>> System.out.println(sql);
>> System.out.println();
>>
>> CreateTableConstraintStep step1 = createTable(table("Supplier"))
>> .column(field("SNUM", INTEGER))
>> .column(field("SNAME", VARCHAR(16).nullable(false)))
>> .column(field("STATUS", INTEGER.nullable(false)))
>> .column(field("CITY", VARCHAR(20).nullable(false)))
>> .constraints(primaryKey(field("SNUM")),
>> unique(field("SNAME")));
>>
>> System.out.println(step1.toString());
>> String sql1 = step1.getSQL();
>> System.out.println(sql1);
>> System.out.println();
>>
>> *These produce this output:*
>>
>> create table "Supplier" (
>>   "SNUM" integer null,
>>   "SNAME" varchar(16) not null,
>>   "STATUS" integer not null,
>>   "CITY" varchar(20) not null,
>>   primary key ("SNUM"),
>>   unique ("SNAME")
>> )
>> create table "Supplier" ("SNUM" integer null, "SNAME" varchar(16) not 
>> null, "STATUS" integer not null, "CITY" varchar(20) not null, primary key 
>> ("SNUM"), unique ("SNAME"))
>>
>> create table Supplier (
>>   SNUM integer null,
>>   SNAME varchar(16) not null,
>>   STATUS integer not null,
>>   CITY varchar(20) not null,
>>   primary key (SNUM),
>>   unique (SNAME)
>> )
>> create table Supplier (SNUM integer null, SNAME varchar(16) not null, 
>> STATUS integer not null, CITY varchar(20) not null, primary key (SNUM), 
>> unique (SNAME))
>>
>> So, I am wondering why the the resulting strings are rendered with and 
>> without quotes.
>>
>> Unless I am missing something, I thought that they should be rendered the 
>> same.  If they are supposed to be different by design, which SQL building 
>> approach is more recommended?
>>
>> What dialect are you using (target RDBMS)?
>>
>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/cb4c17c8-9a41-4202-b8a8-b50536a60a1bn%40googlegroups.com.

Reply via email to