My table format is
CREATE TABLE IF NOT EXISTS `clinicReg` (
`clinicRegId` varchar(10) NOT NULL,
`clinicName` varchar(20) NOT NULL,
`clinicAddress` varchar(500) NOT NULL,
`clinicContactNo` int(20) NOT NULL,
`clinicContactNO1` int(20) NOT NULL,
`clinicMobileNo` int(20) NOT NULL,
`clinicMobileNo1` int(20) NOT NULL,
`clinicCatagories` varchar(50) NOT NULL,
`clinicServices` varchar(500) NOT NULL,
`clinicLogo` longblob NOT NULL,
`ownerName` varchar(20) NOT NULL,
`clinicEmailId` varchar(20) NOT NULL,
`clinicEmailId1` varchar(20) NOT NULL,
`loginTimeStamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`clinicRegId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
my insert query is
insert into 'harshal.clinicreg' (clinicRegId,clinicName,
clinicAddress,clinicContactNo,clinicContactNO1,
clinicMobileNo,clinicMobileNo1,clinicCatagories,
clinicServices,clinicLogo,ownerName,clinicEmailId,
clinicEmailId1,loginTimeStamp)
Values
('ORCCli1','Smile Clinic','Mulund',
3456,544,234,567,'Gen','ABC',
load_file(C:\Users\harshal420\Pictures\Camera Roll\Capture.jpg),
'Smile','abc#xyz.com','def#pqr.com', CURDATE());
It is giving me error 1064 can any one help me???
Your INSERT statement has two issues that I can see upfront:
insert into 'harshal.clinicreg'
You have to wrap the db/table name with backticks, not single-quotes:
insert into `harshal`.`clinicreg`
After this, the load_file() function takes a string-input, but you're passing a literal. Try updating the full query to:
INSERT INTO `harshal`.`clinicreg`
(clinicRegId,clinicName, clinicAddress,clinicContactNo,clinicContactNO1,clinicMobileNo,clinicMobileNo1,clinicCatagories,clinicServices,clinicLogo,ownerName,clinicEmailId, clinicEmailId1,loginTimeStamp)
VALUES
('ORCCli1','Smile Clinic','Mulund', 3456,544,234,567,'Gen','ABC',
load_file('C:\\Users\\harshal420\\Pictures\\Camera Roll\\Capture.jpg'),
'Smile','abc#xyz.com','def#pqr.com', CURDATE()
);
You have 2 errors in your insert query.
1 -
Your table name is wrong it should be
insert into clinicReg
you can also put dbname.clinicReg
2- in your query load_file(C:\Users\harshal420\Pictures\Camera Roll\Capture.jpg)
this gives error
It is happening because you have an error in your SQL syntax. More specifically it is because you have used the incorrect quoting character when quoting your database/table name; you should be using backticks (`) or no quotes when specifying a database name, table name or field name.
You also need to quote the path to your data using single or double quotes. See my example below.
insert into `harshal`.`clinicreg` (clinicRegId,clinicName,clinicAddress,clinicContactNo,clinicContactNO1,clinicMobileNo,clinicMobileNo1,clinicCatagories,clinicServices,clinicLogo,ownerName,clinicEmailId,clinicEmailId1,loginTimeStamp) Values ('ORCCli1','Smile Clinic','Mulund',3456,544,234,567,'Gen','ABC',load_file('C:\Users\harshal420\Pictures\Camera Roll\Capture.jpg'),'Smile','abc#xyz.com','def#pqr.com', CURDATE());
You probably want to do
insert into `harshal`.`clinicreg` (...)
instead of
insert into 'harshal.clinicreg' (...)
In your example MySQL gets a string instead of table identifier which is what it excepts here.
You can also miss backticks here at all.
There also second syntax error in your query. You should quote path string passed to load_file function as parameter. Should be:
load_file('C:\Users\harshal420\Pictures\Camera Roll\Capture.jpg') ,
Related
I am not able to find out what is the exact issue. When I remove index param from below mentioned query and try to insert the data it works fine, but trying to add index cause an error.
Here is my table schema:
CREATE TABLE IF NOT EXISTS `address_list` (
`email` varchar(100) NOT NULL,
`currency_name` varchar(50) NOT NULL,
`address` varchar(50) NOT NULL,
`label` varchar(100) NOT NULL,
`index` int DEFAULT 0,
`address_type` varchar(50) NOT NULL,
`balance` varchar(500) DEFAULT "0.0",
`timestamp` TIMESTAMP default CURRENT_TIMESTAMP
)
and here is my insert query :
insert into address_list (email,currency_name,address,label,index,address_type) Values ('abc#gmail.com','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X','test address',3,'wallet');
error :
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 'index) Values ('abc#gmail.com','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X'' at line 1
index is a reserved word in mysql; rename your column to something else, or else place it in backticks where you want to use it:
insert into address_list (email,currency_name,address,label,`index`,address_type) Values ('abc#gmail.com','bitcoin','mgbtUQt7ppCEhxWmvicxrbEDYSom5kNk8X','test address',3,'wallet');
See https://dev.mysql.com/doc/refman/8.0/en/keywords.html
VALUE is not valid at this position
The error is on VALUES within the INSERT statement. It states it is not supported within this version. Does that mean i require an update or is my syntax wrong?
create schema Cleudo;
USE CLEUDO;
create table Victim(
Vic_ID INT NOT NULL AUTO_INCREMENT,
Vic_Title VARCHAR(10) NOT NULL,
Vic_Name VARCHAR(30) NOT NULL,
Vic_Room VARCHAR(30) NULL,
Vic_TOD VARCHAR(5) NULL,
Vic_Weapon VARCHAR(30) NULL,
PRIMARY KEY ( VIC_ID )
);
INSERT INTO Victim VALUES ('Miss','Scarlet','Library','10:45','candle-Stick');
When I run your code, I get the following error:
Column count doesn't match value count at row 1
This is happening because you are not giving a value to table Vic_ID (which makes sense, because it is auto-incremented). To avoid the error, you need to enumerate the target columns, like so:
INSERT INTO Victim (Vic_Title, Vic_Name, Vic_Room, Vic_TOD, Vic_Weapon)
VALUES ('Miss','Scarlet','Library','10:45','candle-Stick');
Demo on DB Fiddle
You are getting this error because the number of columns are not the same, so you need to change your query to this:
INSERT INTO Victim(Vic_Title,Vic_Name,Vic_Room,Vic_TOD,Vic_Weapon) VALUES ('Miss','Scarlet','Library','10:45','candle-Stick');
In case you want to specify the Vic_ID value you can try this query below instead:
INSERT INTO Victim VALUES (NULL,'Miss','Scarlet','Library','10:45','candle-Stick')
I am having 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 ''tablename'(
'id'MEDIUMINT NOT NULL AUTO_INCREMENT,
'content'TEXT NOT NULL,
'd' at line 1
From this statement:
CREATE TABLE 'tablename'(
'id'MEDIUMINT NOT NULL AUTO_INCREMENT,
'content'TEXT NOT NULL,
'date_added' DATETIME NOT NULL,
'user' VARCHAR (16) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE ('id')
); ENGINE=MyISAM;
Why?
You need the backtick instead of the single quote ('). The backtick is this character:
`
Better yet - don't bother with either:
CREATE TABLE tablename (
id MEDIUMINT ...
Important: also see the comments below from tadman; they round out this answer nicely by explaining the backticks and pointing out another syntax issue.
You are using incorrect notation.
In your create table statement, you are using the single quote ( ').
You can't use that here for table names and column names.
Alternatives would be the tick mark (`). Or just completely remove all notation altogether.
Here is your code, fully functional:
CREATE TABLE tablename (
`id` MEDIUMINT NOT NULL,
`content`TEXT NOT NULL,
`date_added` DATETIME NOT NULL,
`user` VARCHAR (16) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE (`id`)
);
You are missing a space between the columnname and the type of the first two columns. Also, you have a ; to many at the end
CREATE TABLE 'tablename'(
'id' MEDIUMINT NOT NULL AUTO_INCREMENT,
'content' TEXT NOT NULL,
'date_added' DATETIME NOT NULL,
'user' VARCHAR (16) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE ('id')
) ENGINE=MyISAM;
I have the following MySQL query:
INSERT INTO 12:12:12:12:12(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip) VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0')
The name of the table is "12:12:12:12:12".
Here is the schema:
"CREATE TABLE IF NOT EXISTS `$mac` (
`timestamp` int(11) NOT NULL,
`niceTime` varchar(20) NOT NULL,
`temperature` float NOT NULL,
`relative_humidity` int(11) NOT NULL,
`wind_speed` float NOT NULL,
`gust_speed` float NOT NULL,
`rain_mm_per_hour` float NOT NULL,
`nsew` int(11) NOT NULL,
`str` varchar(1000) NOT NULL,
`ip` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
No matter what I do, I cannot get the query to be accepted ;(
Query failed: 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 '12:12:12:12:12(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_' at line 1
Many thanks in advance,
you will use backticks like that to your table name
12:12:12:12:12
try this
INSERT INTO `12:12:12:12:12`(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip) VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0'
EDIT.
Rules for naming objects, including tables in MySql:
http://dev.mysql.com/doc/refman/5.1/en/identifiers.html
Identifiers may begin with a digit but
unless quoted may not consist solely
of digits.
The identifier quote character is the backtick (“`”):
Use backticks around identifiers, especially when using such unconventional table names:
INSERT INTO `12:12:12:12:12`(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip)
VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0')
I know there are lots of bugs like this around here but this query seems to be different, as it's an insert query. Here is the schema for the table card_info:
CREATE TABLE card_info (
card_id mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
card_name_orig varchar(150) NOT NULL,
card_name_html varchar(150) NOT NULL,
card_name_search varchar(150) NOT NULL,
card_name_page varchar(150) NOT NULL,
card_cost varchar(50) DEFAULT NULL,
card_cost_converted tinyint(2) NOT NULL DEFAULT '0',
card_subtype varchar(75) DEFAULT NULL,
card_oracle_text_orig text,
card_oracle_text_html text,
card_power varchar(10) DEFAULT NULL,
card_toughness varchar(10) DEFAULT NULL,
card_loyalty tinyint(1) DEFAULT NULL,
PRIMARY KEY (card_id),
KEY card_name_nd (card_name_search),
KEY card_name_page (card_name_page),
KEY card_cost_converted (card_cost_converted),
KEY card_power (card_power),
KEY card_toughness (card_toughness),
KEY card_loyalty (card_loyalty),
FULLTEXT KEY card_oracle_text_orig (card_oracle_text_orig),
FULLTEXT KEY card_name_search (card_name_search)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
And here is my query:
INSERT INTO card_info (
card_name_orig, card_name_html, card_name_search, card_name_page, card_cost,
card_cost_converted, card_subtype, card_oracle_text_orig, card_oracle_text_html,
card_power, card_toughness, card_loyalty
)
SELECT DISTINCT
d.name_orig, d.name_html, d.name_search, d.name_page, d.cost,
COALESCE(d.cost_converted, 0), d.type_sub, d.oracle_text_orig,
d.oracle_text_html, d.`power`, d.toughness, d.loyalty
FROM card_info_de d
LEFT OUTER JOIN card_info i ON d.name_search = i.card_name_search
WHERE i.card_id IS NULL
AND d.edition_id = 'isd'
ORDER BY (d.collector_number + 0), d.collector_number;
If I perform this query, I'm getting this error:
1292 - Truncated incorrect DOUBLE value: '181a'
Please note that the value 181a is from the column card_info_de.collector_number and it is a VARCHAR(5) field, and that field isn't being inserted to the card_info table anyway, it's just being used in the order clause of the select query.
If I do the query starting from the SELECT only, I can see the correct results are being selected, but when I do the insert, it gives me the error above. Do note that If I remove the ORDER BY clause from the SELECT query, it inserts fine. I don't have a clue what I'm doing wrong.
Thanks in advance.
Just hit the same error myself and it is a bit misleading. I found the answer in another thread:
Error Code 1292 - Truncated incorrect DOUBLE value - Mysql
This message means you're trying to compare a number and a string in a WHERE or ON clause. Either make sure they have similar declarations, or use an explicit CAST to convert the number to a string.
If you turn off strict mode, the error should turn into a warning.
Barmar
So basically check for any of these columns being treated as the wrong data type:
d.name_search
i.card_name_search
d.edition_id
d.collector_number
Try
ORDER BY (d.collector_number + '0'), d.collector_number;
Terrible if true, but quite possible.