List:General Discussion« Previous MessageNext Message »
From:Joerg Bruehe Date:February 15 2011 6:58pm
Subject:Re: Insert only if the entry doesn't exist
View as plain text  
Hi!


Andre Polykanine wrote:
> Hello Rolando,
> 
> So if I do
> "INSERT IGNORE INTO `Votes` SET `EntryId`='12345', UserId`='789'";
> it  *won't* insert the second row if there's a row with EntryId set to
> 12345 and UserId set to 789?

If you want to have at most one vote per user on any entry, IMO you
should have a "unique index" on that combination of fields.


Aside:
Assuming you "*Id" values are numeric types, you should stop using
quotes around them: quotes enclose strings.
I know MySQL implicitly converts numbers to strings and vice versa, but
this costs performance and IMO is a bad idea anyways.
I feel a programmer should know the distinction of numeric and string
types and keep them separate in a well-structured application.


HTH,
Jörg

-- 
Joerg Bruehe,  MySQL Build Team,  joerg.bruehe@stripped
ORACLE Deutschland B.V. & Co. KG,   Komturstrasse 18a,   D-12099 Berlin
Geschaeftsfuehrer: Juergen Kunz, Marcel v.d. Molen, Alexander v.d. Ven
Amtsgericht Muenchen: HRA 95603

Thread
Insert only if the entry doesn't existAndre Polykanine14 Feb
  • Re: Insert only if the entry doesn't existjoao14 Feb
    • RE: Insert only if the entry doesn't existRolando Edwards14 Feb
      • Re: Insert only if the entry doesn't existAndre Polykanine14 Feb
        • RE: Insert only if the entry doesn't existRolando Edwards14 Feb
          • Re: Insert only if the entry doesn't existAndre Polykanine15 Feb
            • Re: Insert only if the entry doesn't existJoerg Bruehe15 Feb