I wrote a little while ago about postgres and there being problems with 
the way that sequence names were being autogenerated. Torque does 
tablename_seq whereas postgresql does tablename_colname_seq for its 
autogenerated sequence names.

I noticed in the source that sequences were being generated by hand and 
that would be fine and fix the problem except that the columns are still 
being set as type serial causing postgres to try and generate it's own 
sequence.

This actually now causes the previous workaround to fail. By setting the 
sequence name torque will generate the sequence and then when the table 
creation tried to generate one it fails because it already exists. Letting 
torque generate the name then it succeeds the first time, but subsequent 
times it fails unless the db is recreated because torque only drops the 
sequence and table it created and the autogenerated sequence is left 
behind to conflict.

Could someone explain to me the motivation for wanting to generate the 
sequences by hand rather than simply letting postgres do it?

[...]

Ok, I see. The sequence name is generated in 
org/apache/torque/engine/database/model/Table.java and the specific column 
name is not available to it.

[...]

Well, crap. The talk before about the proper behavior of primary keys not 
to be autoincremented is the problem. The are now autoincremented using 
the table sequence. Setting autoincerement="true" on a primary key will 
cause the schema to self destruct as detailed above. 

#if (($table.IdMethod == "native") && ($col.isPrimaryKey()))
  #set ( $default = "DEFAULT nextval('$table.SequenceName')" )
#else
  #set ( $default = $col.DefaultSetting )
#end

What is going to happen when someone has a primary key that is not an 
integer?

Putting a check in when using the autoincrement type to make sure that it 
is not a primary key and already autoincremented would likely be a good 
idea.

[...]

I am going to go ahead and post this just to get it in the archives and 
maybe save someone wandering through the code to figure it out.

Will Holcomb


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to