Unable to update a table due to ERROR 1064 (42000) - mysql

I did realized that there have been concern raised regrading this error but this one quite different. I have a table below and unable to update it due to ERROR 1064.
Please help
mysql> desc propertystring;
+---------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+-------+
| ID | decimal(18,0) | NO | PRI | NULL | |
| propertyvalue | text | YES | | NULL | |
+---------------+---------------+------+-----+---------+-------+
2 rows in set (0.01 sec)
UPDATE propertystring SET propertyvalue = 'x.x.x.x/jira' FROM propertyentry PE WHERE PE.id=propertystring.id and PE.property_key = 'jira.baseurl';
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 'FROM propertyentry PE WHERE
PE.id=propertystring.id and PE.property_key = 'jira.' at line 1
Have tried different quotes but cannot update the feild. is it because field type is "text" ?

Thanks guys for the hint. #John Conde you are right the correct way to do this is as below without FROM clause UPDATE propertystring PS JOIN propertyentry PE ON PE.id=PS.id and PE.property_key = 'jira.baseurl' SET PS.propertyvalue = 'x.x.x.x/jira';

Related

MySQL throwing syntax error while trying to alter a table

I have been trying to alter a table to include a date column with default value of CURDATE() but MySQL is constantly throwing syntax error. Now, I have checked syntax for altering a table from several sources but I believe I do not have any syntax error. When I remove the default value part, the query runs fine but for some reason it cannot add a default value for the date column. I don't know why that is the case.
The code:
mysql> describe test;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| col1 | int | YES | | 0 | |
| col2 | varchar(100) | YES | | hello | |
| col3 | varchar(5) | YES | | T | |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.02 sec)
mysql> ALTER TABLE test ADD COLUMN col4 DATE DEFAULT CURDATE();
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 'CURDATE()' at line 1
mysql>
Edit: My MySQL version: 8.0.31
I think it has to be like this now:
ALTER TABLE test ADD COLUMN col4 DATE DEFAULT (CURRENT_DATE);
Note the parenthesis, or (curdate())

I cannot change databases column

I cannot change databases column
My Env
MacOS Mojave, MySQL Server version: 10.1.39-MariaDB Source distribution
why
Making a CRUD app, but I want to change table column,
from text to desc, so I searched and used alter
command, but right SQL command returns error messages.
My table
MariaDB [cake_cms]> describe interns;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| email | varchar(255) | NO | | NULL | |
| name | varchar(64) | NO | | NULL | |
| text | varchar(255) | NO | | NULL | |
| location | varchar(64) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
MariaDB [cake_cms]> Alter Table interns Rename Column text to desc;
ERROR 1064 (42000): 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 'Column text to desc' at line 1
Refered
https://www.dbonline.jp/mysql/table/index18.html
says to use
ALTER TABLE table_name
CHANGE COLUMN old_name TO new_name;
Rename a column in MySQL
This site says:
ALTER TABLE tableName RENAME COLUMN "oldcolname" TO "newcolname" datatype(length);
So I write
alter table interns rename column "name" to "newname" varchar(255);
But returned syntax error message....
I do not know what to do. Please help me!
desc is a sql command so you can't name your table like this

Changing a field in mysql using mysql cmd line

I'm trying to get more familiar with using command line.. so i'm kind of new.
How would i update this field 'value' from 1 to 0?
mysql> SELECT * FROM core_config_data WHERE path = 'web/seo/use_rewrites'
-> ;
+-----------+---------+----------+----------------------+-------+
| config_id | scope | scope_id | path | value |
+-----------+---------+----------+----------------------+-------+
| 18 | default | 0 | web/seo/use_rewrites | 1 |
+-----------+---------+----------+----------------------+-------+
1 row in set (0.01 sec)
I tried this update statement but it didn't work:
UPDATE core_config_data SET value='0' WHERE config_id=18;
I threw this error in command line:
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 'WHEREc WHERE config_id=18' at line 1

Compilation Error in MYSQL trigger?

Table structure is:
mysql> DESC groups;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| PKey | varchar(64) | NO | PRI | NULL | |
| group_name | varchar(64) | YES | | NULL | |
| Region | varchar(128) | NO | | NULL | |
| Role | varchar(128) | NO | | NULL | |
| parent_group | varchar(64) | NO | MUL | NULL | |
+--------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
When i am executing this Trigger , i'm having a compilation error
DELIMITER $$
CREATE
TRIGGER `group_before_delete` BEFORE DELETE
ON `groups`
FOR EACH ROW BEGIN
IF old.parent_group=old.PKey THEN
UPDATE `Error: deletion RootGroup is prohibited!`;
ELSE
UPDATE groups
SET parent_group=old.parent_group
WHERE parent_group=old.Pkey;
END IF;
END$$
DELIMITER ;
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 ';
ELSE
t_group=old.parent_group
t_group=old.PKey;
END IF;' at line 6
mysql> DELIMITER ;
Can you tell me what i'm missing here ??
You get an error in your code because the syntax of your UPDATE statement is not valid.
The links you give are 4 and 5 years old!
Since the SIGNAL statement is available in MySQL since version 5.5.0 (released 3 years ago), this is really not a good idea to use the hacks described in these 2 webpages. Instead, use the SIGNAL statement.
Note: From the comments we learn that the OP is not using MySQL 5.5, so SIGNAL is not available.
In your IF statement, the following is not a valid SQL statement:
UPDATE `Error: deletion RootGroup is prohibited!`;
This should be this:
IF old.parent_group=old.PKey THEN
UPDATE `Error: deletion RootGroup is prohibited!` set x=1;
ELSE
UPDATE groups
SET parent_group=old.parent_group
WHERE parent_group=old.PKey;
END IF;
I have never done things this way. It is a bit of an ugly way of doing it. But if it works, what the heck.

Mind writing my sql statement for me?

This kind of sad but I've been at it a while and I just can't seem to figure this statement out, google searches turn up similar questions but I haven't successfully applied the solutions.
I have a table of music, and every time I insert a song into it(each row is a song) I want to insert the song into a table of clean music if it is flagged as clean. I'm using mysql.
use music;
CREATE TRIGGER cache_clean_music BEFORE INSERT ON music
FOR EACH ROW
if new.clean then
insert into clean_music values (new.artist, new.album, new.song, new.filename, new.clean);
end if;
The Error I get is
ERROR 1064 (42000) at line 3: 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 '' at line 4
and here is a description of the music table, the clean_music table is exactly the same
+----------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+----------------+
| artist | varchar(100) | YES | | NULL | |
| album | varchar(100) | YES | | NULL | |
| song | varchar(100) | YES | | NULL | |
| filename | varchar(100) | YES | | NULL | |
| clean | tinyint(1) | YES | | NULL | |
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
+----------+---------------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
If the two tables are identical (or almost), you probably do not need triggers (and all their mess) at all.
You may use a VIEW instead of a table (with duplicate data) for cache_clean_music:
CREATE VIEW cache_clean_music AS
SELECT artist
, album
, song
, filename ---- and possibly other fields you need
, id
FROM music
WHERE clean ;
Adding an index on music.clean would be a good idea in this case.
Does it help if you wrap a BEGIN...END around things?
CREATE TRIGGER ...
FOR EACH ROW BEGIN
IF ...
....
END IF;
END
The error - ERROR 1064 (42000) at line 3: 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 '' at line 4 - means that the values in some of your input params isn't correct, perhaps there is some mismatching single quote. Can you display your query or the value in the NEW. variables?
Also, once you have fixed that error, your query will also return another error that "the column count doesn't match value count". And that will be because your table has 6 columns but your INSERT has only 5. Mention the columns in your INSERT query and it should be fine, like:
insert into clean_music (artist, album, song, filename, clean) values (new.artist, new.album, new.song, new.filename, new.clean);
Your clue is this
" check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4"
Do you know what version of mysql server you are running?
Did you check the manual to make sure that the command you have written is allowed in that version?