Jump to content
LLLLLLL

Trigger UUID result is same value for every row, not unique for each

Recommended Posts

I have a trigger, 

 

CREATE TRIGGER `TRIGGER_SOMETABLE_UID` BEFORE INSERT ON `SOMETABLE`
 FOR EACH ROW SET NEW.Uid = UUID(  )
 
Now, I thought this would fire FOR EACH ROW, but if I'm doing an insert like this...
 
insert into sometable ( col1, col2 )
( select col1, col2 from SOME_OTHER_tABLE )
 
... and that inserts two rows, the result is that Uid in both new rows is identical. This is not the desired behavior. Can you tell me how to get a unique Uid in each row?

Share this post


Link to post
Share on other sites

the result is that Uid in both new rows is identical.

 

Not on my system.

 

Are you sure that the values are in fact identical, not just similar? You realize that the old UUIDs used by MySQL are mostly deterministic and will only differ in some parts, right? And how does your table even accept identical values? An ID column should be the primary key or at least unique.

Share this post


Link to post
Share on other sites

They are identical. (In fact, I can't set the column to unique right now because the values are duplicate.)

 

You created the trigger in the exact same way, and your Uid was different when inserting two rows?

Share this post


Link to post
Share on other sites

In fact, adding the unique constraint does nothing. The trigger STILL adds identical values. Whoa.

 

And now it stopped...?

 

I'm going to do some MySql maintenance or something...

Edited by timneu22

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.