Learning IN values - mysql

I'm trying to do a IN values statement. This is my query:
I did mysql_escape_string on each of the elements in the IN so mysql_escape_string('http://www.blah.com/%s') gave me http://www.blah.com/%s
SELECT * FROM social_handlers WHERE (`group` = 0 OR `url_template` IN ("http://www.blah.com/%s", "totally bogus val")) AND update_time > 0
It keeps telling me this error though:
MySQL Error: 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 'url_template IN ("http://www.blah.com/%s", "totally bogus val")) AND update_ti' at line 1
How can I identify this error?
This is my social_handlers table:
I also had to do mysql_set_charset('utf8',$connectid); because i support Russian and Chinese characters.

Related

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL serve

I am trying to execute the following code but not sure where i am going wrong. Mysql workbench is throwing error for the following code
Insert into abc(Date,Close_Price,Signal)
Select
Date,
close_price,
case
when dayma_20 > dayma_50 then 'BUY'
when dayma_20 < dayma_50 then 'SELL'
else 'HOLD'
end as Signal
from stock;
It is giving error as follows:
Error Code: 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 'Signal) Select date,close_price, case when dayma_20 > dayma_50 then 'BUY' when d' at line 1
SIGNAL is a MySQL reserved word. You need to enclose it between backticks (which, by the way, makes it case-sensitive, meaning that you must use the same case as the one that was used when the table was created).
insert into abc(Date,Close_Price,`Signal`) select ...
A better option would be rename that column to something that is not reserved. Using reserved words as object names in a schema is tedious and error prone.
Side note: DATE is also a reserved word.

MySQL: Get POSITION of Non-ASCII character

I have an example string like,
"Kim_!#$Maria"
The '_' could be anything that is not a letter or a number. So I want to find the position of the first non-Numeric/Alphabet character.
We are using MariaDB 5.5. The option to upgrade to version 10+ is beyond the scope of this question, as we are bound by the client's specifications.
Tried this but I get syntax errors.
LOCATE(REGEXP "[\\x00-\\xFF]|^$", myField))
Category Timestamp Duration Message Line Position Error 24/07/2019
4:08:38 PM 0:00:04.612 MySQL Database 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 'REGEXP "[\x00-\xFF]|^$",
ced.Deckhand)) as FirstWord FROM Crew_Emergency_Dril' at line 1 15 81
I am an SQL Server guy - not familiar with MySQL syntax.

"select cast(UUID() as VARBINARY(100))" MySQL query error

Error:
Error Code: 1064. 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 'VARBINARY(10))' at line 1
VARBINARY isn't a type (data types in columns are slightly different)
I think you want something like:
select cast(UUID() as CHAR(36) CHARACTER SET BINARY)

Extract data between two phrases in MySQL?

I am trying to extract data between two sets of characters in MySQL. To keep the example somewhat simple, I am looking for the text between and in a column called STAGE_DATA.
Here is the SQL I have now:
SELECT
SUBSTR(STAGE_DATA,
LOCATE('<title>',STAGE_DATA)+1,
(CHAR_LENGTH(STAGE_DATA) - LOCATE('<title>',REVERSE(STAGE_DATA))
- LOCATE('</title>,STAGE_DATA)))
FROM Stage_Table
But it is giving an 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 ''</title>,STAGE_DATA))) FROM Stage_Table' at line 5
Why?
Thank you!

sql syntax error storing html table as text in mysql

Query to insert text in database is:
INSERT INTO uri VALUES('')
I'm getting follwing Syntax error:
MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
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 'liq" style="font-size:110%;font-family:'Alvi Nastaleeq', 'Nafees Nastaleeq', 'Na' at line 1
change this
title=\"Nasta'liq\"
^-----you have single quote alone here .get rid of it
to
title=\"Nasta liq\"
or
title=\"Nastaliq\"