1

I'm trying to make the following transaction work, but the I get a mysql error near SELECT. I've double-checked that all column names are correct.

Error message

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO articles (catid,content,title,keywords,isactive) (SELEC' at line 2

SQL

START TRANSACTION; 
INSERT INTO articles (catid,content,title,keywords,isactive) 
(SELECT 1, pendingarticles.content, pendingarticles.title, 
pendingarticles.keywords, 1 
FROM pendingarticles 
WHERE pendingarticles.id=1);
DELETE FROM pendingarticles WHERE id=1; 
COMMIT;

UPDATE

The code itself works. Both the INSERT INTO - SELECT part, and the DELETE part. Something's wrong with the transaction. Perhaps ;? Or my db server can't do transactions?

Rápli András
  • 3,869
  • 1
  • 35
  • 55

3 Answers3

2

MyISAM Engine does not support transactions. MyIsam engine transaction support

To support transactions you have to change the engine f.e. to InnoDB. Setting the Storage Engine

Community
  • 1
  • 1
Koryu
  • 1,371
  • 1
  • 11
  • 21
0

you want:

INSERT INTO articles (catid,content,title,keywords,isactive)  
SELECT 1,pendingarticles.content,pendingarticles.title,  
        pendingarticles.keywords,1  
FROM pendingarticles  
WHERE pendingarticles.id=1;  
DELETE FROM pendingarticles WHERE id=1; 

The extra set of parenthesis you provided is not necessary.

Woot4Moo
  • 23,987
  • 16
  • 94
  • 151
-1

I believe that the parentheses around the Select are not necessary.

http://dev.mysql.com/doc/refman/5.6/en/insert.html

START TRANSACTION; 
INSERT INTO articles (catid,content,title,keywords,isactive) 
SELECT 1, pendingarticles.content, pendingarticles.title, 
pendingarticles.keywords, 1 
FROM pendingarticles 
WHERE pendingarticles.id=1;
DELETE FROM pendingarticles WHERE id=1; 
COMMIT; 
Petio Ivanov
  • 305
  • 1
  • 5