Thanks Jesse; Your suggestion works.
On Wed, Nov 18, 2009 at 3:11 AM, Jesse Long <[email protected]> wrote: > Hi Merkel, > > I'm sorry, I dont know what the "AS random_uuid()" is about, but it > sound like this is what you are looking for: > > create table malade (id varchar(36) default random_uuid() not null primary > key, name varchar(200) ); > > s/as/default/ > > Cheers, > Jesse > > Merkel wrote: > > Hi, > > > > here is what is happening, let me know if this is normal. > > > > 1) create a table with a field id of type char and as random_uuid() > > 2) insert a row in this table > > 3) update the inserted row. > > > > After each update, the value of the id changes. How can i contrain H2, > > not to change the value of the id field once it is assigned? > > > > Here are some few lines of code to test this: > > > > [code] > > > > import java.io.File; > > import java.sql.*; > > > > public class StrangeHold { > > public static void main(String[] a) throws Exception { > > Class.forName("org.h2.Driver"); > > > > Connection conn = DriverManager. > getConnection("jdbc:h2:/temp/ > > test", "sa", ""); > > Statement s=conn.createStatement(); > > s.executeUpdate("create table malade (id varchar(36) as > > random_uuid() not null primary key, name varchar(200) )"); > > s.executeUpdate("insert into malade (name) values > > ('zlarge')"); > > conn.commit(); > > ResultSet rs=s.executeQuery("select id from malade"); > > rs.next(); > > String id=rs.getString(1); > > System.out.println(id); > > s.executeUpdate("update malade set name='no zlarge'"); > > rs=s.executeQuery("select id from malade"); > > rs.next(); > > id=rs.getString(1); > > System.out.println(id); > > conn.close(); > > > > } > > } > > > > > > [/code] > > > > -- > > > > You received this message because you are subscribed to the Google Groups > "H2 Database" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > [email protected]<h2-database%[email protected]> > . > > For more options, visit this group at > http://groups.google.com/group/h2-database?hl=. > > > > > > > > -- > > You received this message because you are subscribed to the Google Groups > "H2 Database" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<h2-database%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/h2-database?hl=. > > > -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/h2-database?hl=.
