| Bug #4258 | Let EXIST work with INSERT | ||
|---|---|---|---|
| Submitted: | 23 Jun 2004 11:14 | Modified: | 13 Dec 2005 16:41 |
| Reporter: | Kalle B | Email Updates: | |
| Status: | Won't fix | Impact on me: | |
| Category: | MySQL Server | Severity: | S4 (Feature request) |
| Version: | OS: | Linux (FC2) | |
| Assigned to: | CPU Architecture: | Any | |
[13 Dec 2005 16:41]
Valeriy Kravchuk
Thank you for a feature request. Sorry, but I do not think any other way to deal with this kind of problems (besides REPLACE) is really needed. Please, declare primary keys for all your tables - it is a right way to use a relational database. And then just use REPLACE.

Description: I want to insert a row only if it doesn't exist. I have tried something like this with variations but all fail. How to repeat: INSERT INTO t1 SET col = 'a' IF NOT EXISTS ( SELECT * FROM t1 WHERE col = 'a' ) or at least: INSERT INTO t1 SET col = 'a' WHERE ( SELECT COUNT(*) FROM t1 WHERE col = 'a' ) = 0 Suggested fix: I know that there is the REPLACE syntax, but I don't use unique keys and nevertheless REPLACE wouldn't be as versatile as this syntax. Therefore I make it a feature request.