MySQL "INSERT INTO position" fails - mysql

I am trying to insert data in a table but getting error 1064:
INSERT INTO position(positioncode,description)
VALUES ('5000', 'President');
The error message says:
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 'position(positioncode,description) VALUES ('5000',
'President')' at line 1
I have also insert data in other tables on the same way. Can someone help?

position is the name of a function. Quote it by enclosing it inside backticks:
INSERT INTO `position` (positioncode, description) VALUES ('5000', 'President');
The exact behavior of function name parsing is described here:
Function Name Parsing and Resolution.
The description seems to suggest that:
CREATE TABLE count (i INT) could be an error or not depending on IGNORE SPACE setting
CREATE TABLE count(i INT) is always an error
So instead of guessing, always quote built-in function names.

Related

Unable to determine cause of syntax error

I am running an insert query to add data into my database but I get the following error
"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' at line 1")"
I have reviewed the code but unable to determine why
cursor.execute("INSERT IGNORE INTO footballtest(`codmeci` ,`datameci`,`orameci` ,`sezonul` ,`etapa` ,`txtechipa1`,`txtechipa2` ,`scor1` ,`scor2` ,`scorp1` ,`scorp2` ,`codechipa1` ,`codechipa2` ,`cotaa` ,`cotae`,`cotad`,`cotao` ,`cotau` ,`suth` ,`suta` ,`sutht`,`sutat` ,`corh` ,`cora` ,`foulsh` ,`foulsa` ,`yellowh`,`yellowa` ,`ballph`,`ballpa` ,`mgolh` ,`mgola` ,`mgol`) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"), (row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10],row[13],row[14],row[16],row[17],row[18],row[19],row[20],row[29],row[30],row[31],row[32],row[33],row[34],row[35],row[36],row[37],row[38],row[39],row[40],row[57],row[58],row[59])
Sometimes taking a large problem and simplifying it can reveal what the problem is. Here is your insert, but using only three columns:
sql = "INSERT IGNORE INTO footballtest(codmeci, datameci, orameci) VALUES (%s,%s,%s)"
cursor.execute(sql, (row[0], row[1], row[2]))
Note carefully that the pattern is:
cursor.execute(<some SQL string>, (some CSV tuple of values to bind))

Need help inserting json literal into mysql 5.7

When I try to insert the following query I keep getting this 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 '['php','javascript'])' at line 2
I am using the following query
INSERT INTO freelancer (tags) VALUES (['php','javascript']);
I tried another query, this time making it a string, and then I get this error
INSERT INTO freelancer (tags) VALUES ("['php','javascript']");
Invalid JSON text: "Invalid value." at position 1 in value for column 'freelancer.tags'.
I am not sure how to go about inserting this into mysql... if anyone can help me figure this out, I would really appreciate it!
JSON is very particular about quotes. You must use doubles:
VALUES ('["php","javascript"]')
You can test with a JSON validator if you're curious about what is or isn't JSON.

how to add foreign key in a table using insert and select statement?

i have tried this
INSERT INTO PARENT (FamilyID,userName, email, password)VALUES ((SELECT FamilyID FROM 'FAMILY' WHERE familyName=‘Idiots13’),'abc12','abc12#gmail.com', 'abc123#’);
I'm getting this error:
#1064 - 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 ''FAMILY' WHERE familyName=‘Idiots13’), 'deeepak13','deepak13#gmail.com', '' at line 3
please help!!
You used wrong type of quotes around ‘Idiots13’, you need to use ' instead of ‘ and ’.
The same problem is also in the ending quote of 'abc123#’.

phpadmin 1064 error UUID trigger

I'm trying to create the following trigger in PHP admin but get the following error. I've set delimiter to '//' but still no luck. Any help?
For your information the table is called 'users' and I'm trying to add the UUID to the primary key 'user_id'
CREATE TRIGGER user_id_users_insert BEFORE INSERT ON 'users'
FOR EACH ROW
BEGIN
SET NEW.user_id=UUID();
END;
#1064 - 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 ''users'
FOR EACH ROW
BEGIN
SET NEW.user_id=UUID();
END' at line 1
Quoting 'users' with single-quote ' characters results in it being parsed as a string literal (which is not valid in the ON clause of a CREATE TRIGGER statement) rather than as an SQL object identifier (such as a table name, which is what MySQL expects to see) which, if quoted, must instead use the backtick ` character (or, alternatively, double-quote " characters if MySQL's ANSI_QUOTES SQL mode is enabled). See When to use single quotes, double quotes, and backticks? -- #eggyal

MySQL Syntax Error, Can't Figure it Out

I have the following MySQL statement to insert a lot of data into a lot of columns in a table:
INSERT INTO survey (lang,check,lname,fname,age,dob,dlang1,dlang2,dlang3,dlang4,dlang5,alang1,alang2,alang3,alang4,alang5,expperc1,expperc2,expperc3,expperc4,expperc5,readperc1,readperc2,readperc3,readperc4,readperc5,speakperc1,speakperc2,speakperc3,speakperc4,speakperc5,culture1,culture2,culture3,culture4,culture5,eduyears,eduother,immi, ...
I get the following error when I try to run the statement:
ERROR 1064 (42000): 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 survey
(lang,check,lname,fname,age,dob,dlang1,dlang2,dlang3,dlang4,' at line
1
I thought that to insert data into specific columns I'm supposed to list out all of the column names in ()s, as I've done. Am I missing something here?
For reference, here's the full statement, although the syntax error should have been reached before most of this, right?
INSERT INTO survey (lang,check,lname,fname,age,dob,dlang1,dlang2,dlang3,dlang4,dlang5,alang1,alang2,alang3,alang4,alang5,expperc1,expperc2,expperc3,expperc4,expperc5,readperc1,readperc2,readperc3,readperc4,readperc5,speakperc1,speakperc2,speakperc3,speakperc4,speakperc5,culture1,culture2,culture3,culture4,culture5,eduyears,eduother,immi,emi,correction,level1,ageacq1,agefluent1,ageread1,agereadf1,ycountry1,mcountry1,yfamily1,mfamily1,yschool1,mschool1,speak1,understand1,read1,learnfriends1,learntapes1,learnfamily1,learntv1,learnread1,learnradio1,expofriends1,exporadio1,expofamily1,exporead1,expotv1,expotapes1,accent1,level2,ageacq2,agefluent2,ageread2,agereadf2,ycountry2,mcountry2,yfamily2,mfamily2,yschool2,mschool2,speak2,understand2,read2,learnfriends2,learntapes2,learnfamily2,learntv2,learnread2,learnradio2,expofriends2,exporadio2,expofamily2,exporead2,expotv2,expotapes2,accent2,comb_str,comb_time,wrench_str,wrench_time,snowman_str,snowman_time,raccoon_str,raccoon_time,watch_str,watch_time,horse_str,horse_time,church_str,church_time,iron_str,iron_time,wateringcan_str,wateringcan_time,stroller_str,stroller_time,saw_str,saw_time,wolf_str,wolf_time,stove_str,stove_time,donkey_str,donkey_time,anchor_str,anchor_time,boot_str,boot_time,needle_str,needle_time,pillar_str,pillar_time,thimble_str,thimble_time,window_str,window_time,pencil_str,pencil_time,squirrel_str,squirrel_time,cup_str,cup_time,clothespin_str,clothespin_time,ball_str,ball_time,penguin_str,penguin_time,cow_str,cow_time,salt_str,salt_time,tiger_str,tiger_time,icecreamcone_str,icecreamcone_time,sink_str,sink_time,spider_str,spider_time,cloud_str,cloud_time,fan_str,fan_time,tweezers_str,tweezers_time,pen_str,pen_time,ant_str,ant_time,caterpillar_str,caterpillar_time,spoon_str,spoon_time,pipe_str,pipe_time,snake_str,snake_time,lips_str,lips_time,sword_str,sword_time,palmtree_str,palmtree_time,barn_str,barn_time,orange_str,orange_time,cat_str,cat_time,flower_str,flower_time,apple_str,apple_time,wood_str,wood_time,grasshopper_str,grasshopper_time,leopard_str,leopard_time,lightswitch_str,lightswitch_time,onion_str,onion_time,washingmachine_str,washingmachine_time,nose_str,nose_time,seahorse_str,seahorse_time,windmill_str,windmill_time,sun_str,sun_time,toothbrush_str,toothbrush_time,ruler_str,ruler_time,boat_str,boat_time,elephant_str,elephant_time,crab_str,crab_time,bug_str,bug_time,monkey_str,monkey_time,rope_str,rope_time,heart_str,heart_time,fish_str,fish_time,plug_str,plug_time,jacket_str,jacket_time,helicopter_str,helicopter_time,rhinoceros_str,rhinoceros_time,corkscrew_str,corkscrew_time,envelope_str,envelope_time,wagon_str,wagon_time,belt_str,belt_time,antlers_str,antlers_time,stocking_str,stocking_time,saltshaker_str,saltshaker_time,car_str,car_time,refrigerator_str,refrigerator_time,airplane_str,airplane_time,pig_str,pig_time,cherry_str,cherry_time,circle_str,circle_time,stool_str,stool_time,gun_str,gun_time,balloon_str,balloon_time,crib_str,crib_time,vest_str,vest_time,snail_str,snail_time,hippo_str,hippo_time,tennisracket_str,tennisracket_time,fence_str,fence_time,gorilla_str,gorilla_time,bear_str,bear_time,chest_str,chest_time,brush_str,brush_time,ostrich_str,ostrich_time,priest_str,priest_time,mountain_str,mountain_time,x_str,x_time,chisel_str,chisel_time,bed_str,bed_time,eye_str,eye_time,basket_str,basket_time,asparagus_str,asparagus_time,scissors_str,scissors_time,couch_str,couch_time,flashlight_str,flashlight_time,box_str,box_time,grave_str,grave_time,watermelon_str,watermelon_time,knife_str,knife_time,leg_str,leg_time,blouse_str,blouse_time,violin_str,violin_time,rock_str,rock_time,tomato_str,tomato_time,parachute_str,parachute_time,dustpan_str,dustpan_time,vase_str,vase_time,sewingmachine_str,sewingmachine_time,house_str,house_time,backpack_str,backpack_time,door_str,door_time,diaper_str,diaper_time,curtains_str,curtains_time,nail_str,nail_time,bowl_str,bowl_time,dresser_str,dresser_time,butterfly_str,butterfly_time,ladle_str,ladle_time,toaster_str,toaster_time,leaf_str,leaf_time,cannon_str,cannon_time,square_str,square_time,whistle_str,whistle_time,triangle_str,triangle_time,glasses_str,glasses_time,skateboard_str,skateboard_time,skunk_str,skunk_time,clown_str,clown_time,dime_str,dime_time,grapes_str,grapes_time,ironingboard_str,ironingboard_time,closet_str,closet_time,safetypin_str,safetypin_time,hair_str,hair_time,shirt_str,shirt_time,rollingpin_str,rollingpin_time,bell_str,bell_time,gas_str,gas_time,hook_str,hook_time,glass_str,glass_time,bucket_str,bucket_time,worm_str,worm_time,top_str,top_time,garbage_can_str,garbage_can_time,barrel_str,barrel_time,strawberry_str,strawberry_time,well_str,well_time,ax_str,ax_time,seal_str,seal_time,necklace_str,necklace_time,cake_str,cake_time,ring_str,ring_time,genie_str,genie_time,beard_str,beard_time,pitcher_str,pitcher_time,pear_str,pear_time,tape_str,tape_time,pliers_str,pliers_time,giraffe_str,giraffe_time,train_str,train_time,owl_str,owl_time,celery_str,celery_time,wheel_str,wheel_time,bricks_str,bricks_time,skirt_str,skirt_time,truck_str,truck_time,clock_str,clock_time,bicycle_str,bicycle_time,egg_str,egg_time,kettle_str,kettle_time,shoe_str,shoe_time,lettuce_str,lettuce_time,lawnmower_str,lawnmower_time,tent_str,tent_time,tie_str,tie_time,table_str,table_time,lemon_str,lemon_time,wheelchair_str,wheelchair_time,scale_str,scale_time,peacock_str,peacock_time,frying_pan_str,frying_pan_time,spiderweb_str,spiderweb_time,broom_str,broom_time,tear_str,tear_time,screwdriver_str,screwdriver_time,sled_str,sled_time,arm_str,arm_time,peach_str,peach_time,lock_str,lock_time,bread_str,bread_time,thumb_str,thumb_time,chicken_str,chicken_time,teapot_str,teapot_time,fishingpole_str,fishingpole_time,football_str,football_time,deer_str,deer_time,turtle_str,turtle_time,pumpkin_str,pumpkin_time,peas_str,peas_time,zebra_str,zebra_time,paintbrush_str,paintbrush_time,chain_str,chain_time,eskimo_str,eskimo_time,rollerskate_str,rollerskate_time,peanut_str,peanut_time,vacuum_str,vacuum_time,football_helmet_str,football_helmet_time,cactus_str,cactus_time,doorknob_str,doorknob_time,tv_str,tv_time,sailboat_str,sailboat_time,piano_str,piano_time,suitcase_str,suitcase_time,mosquito_str,mosquito_time,lipstick_str,lipstick_time,nut_str,nut_time,purse_str,purse_time,sandwich_str,sandwich_time,mitten_str,mitten_time,kangaroo_str,kangaroo_time,crown_str,crown_time,flag_str,flag_time,button_str,button_time,cigarette_str,cigarette_time,baseball_bat_str,baseball_bat_time,ghost_str,ghost_time,turkey_str,turkey_time,hammer_str,hammer_time,saddle_str,saddle_time,bird_str,bird_time,fork_str,fork_time,hand_str,hand_time,mixer_str,mixer_time,recordplayer_str,recordplayer_time,swan_str,swan_time,rockingchair_str,rockingchair_time,mask_str,mask_time,guitar_str,guitar_time,fly_str,fly_time,duck_str,duck_time,floor_str,floor_time,bottle_str,bottle_time,hat_str,hat_time,fox_str,fox_time,camel_str,camel_time,net_str,net_time,typewriter_str,typewriter_time,mushroom_str,mushroom_time,igloo_str,igloo_time,panda_str,panda_time,paint_str,paint_time,fishtank_str,fishtank_time,ladder_str,ladder_time,cigar_str,cigar_time,artichoke_str,artichoke_time,hanger_str,hanger_time,flute_str,flute_time,telephone_str,telephone_time,policeman_str,policeman_time,key_str,key_time,carrot_str,carrot_time,pot_str,pot_time,potato_str,potato_time,zipper_str,zipper_time,pants_str,pants_time,bone_str,bone_time,fire_str,fire_time,ear_str,ear_time,toilet_str,toilet_time,doll_str,doll_time,pineapple_str,pineapple_time,lion_str,lion_time,binoculars_str,binoculars_time,hamburger_str,hamburger_time,walnut_str,walnut_time,camera_str,camera_time,chair_str,chair_time,ashtray_str,ashtray_time,bee_str,bee_time,umbrella_str,umbrella_time,globe_str,globe_time,harp_str,harp_time,motorcycle_str,motorcycle_time,lobster_str,lobster_time,sock_str,sock_time,slide_str,slide_time,alligator_str,alligator_time,rabbit_str,rabbit_time,block_str,block_time,arrow_str,arrow_time,banana_str,banana_time,crackers_str,crackers_time,sheep_str,sheep_time,thread_str,thread_time,puzzle_str,puzzle_time,sweater_str,sweater_time,radish_str,radish_time,porcupine_str,porcupine_time,foot_str,foot_time,bus_str,bus_time,lamp_str,lamp_time,kite_str,kite_time,desk_str,desk_time,trumpet_str,trumpet_time,rake_str,rake_time,canopener_str,canopener_time,wheat_str,wheat_time,railroadtracks_str,railroadtracks_time,lightbulb_str,lightbulb_time,finger_str,finger_time,tree_str,tree_time,trash_str,trash_time,goat_str,goat_time,star_str,star_time,glove_str,glove_time,swing_str,swing_time,moon_str,moon_time,mouse_str,mouse_time,waffle_str,waffle_time,screw_str,screw_time,eagle_str,eagle_time,dog_str,dog_time,corn_str,corn_time,toe_str,toe_time,coat_str,coat_time,stoplight_str,stoplight_time,road_str,road_time,frog_str,frog_time,earring_str,earring_time,rooster_str,rooster_time,music_str,music_time,book_str,book_time,candle_str,candle_time,drum_str,drum_time)
VALUES ("0","on","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","2228","","518","","37","","36","","37","","39","","35","","37","","37","","36","","44","","30","","37","","37","","37","","41","","32","","37","","47","","27","","37","","37","","36","","37","","37","","37","","37","","37","","36","","41","","33","","37","","37","","37","","37","","36","","37","","38","","36","","38","","36","","36","","37","","37","","37","","37","","37","","37","","37","","37","","37","","37","","39","","35","","37","","37","","36","","37","","37","","37","","37","","37","","36","","38","","36","","39","","35","","37","","37","","36","","37","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","36","","37","","39","","35","","37","","37","","37","","36","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","39","","35","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","37","","37","","36","","37","","37","","46","","27","","37","","39","","35","","37","","36","","38","","37","","37","","37","","37","","36","","37","","37","","37","","39","","35","","36","","38","","36","","36","","37","","39","","37","","35","","37","","37","","37","","37","","36","","37","","37","","37","","38","","36","","37","","36","","38","","36","","37","","37","","36","","37","","37","","37","","37","","36","","37","","37","","37","","38","","36","","37","","39","","34","","37","","37","","37","","36","","52","","22","","37","","37","","37","","37","","36","","37","","38","","36","","37","","37","","36","","37","","37","","37","","37","","37","","36","","37","","37","","39","","35","","37","","37","","37","","39","","35","","37","","37","","37","","36","","37","","37","","37","","37","","36","","37","","37","","36","","37","","37","","37","","37","","36","","37","","37","","37","","39","","44","","28","","36","","37","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","38","","36","","36","","41","","33","","39","","36","","37","","37","","36","","36","","36","","37","","38","","36","","37","","37","","36","","40","","35","","37","","36","","37","","37","","36","","37","","37","","40","","35","","36","","43","","30","","39","","36","","36","","37","","36","","37","","49","","25","","37","","39","","36","","36","","40","","34","","37","","36","","37","","37","","37","","37","","36","","39","","35","","37","","37","","37","","36","","37","","37","","36","","41","","35","","36","","37","","37","","36","","39","","36","","36","","37","","37","","36","","37","","37","","37","","37","","37","","45","","28","","37","","36","","37","","39")
Thanks in advance!
Judging from the error message your immediate problem is caused by fact that you have extra double quotes around your INSERT statement or at least at the begging right in front of INSERT
"INSERT INTO survey (lang,check,lname,fname,age,dob,dlang1,dlang2,dlang3,dlang4,
^^
Other than that check is a reserved word in MySQL, so put it in backticks '`'.
Also you better put values in single quotes rather than double quotes.
That being said your INSERT statement should rather look like
INSERT INTO survey (lang,`check`,lname,...) VALUES ('0','on','',...)
^ ^ ^ ^ ^ ^ ^ ^^
Please quote all columns name. see exp below
INSERT INTO survey (`lang`,`check`,`lname`,`fname`,`age`,`dob`...