Below query is running successful in phpMyAdmin 3.5.3 version.
SELECT *
FROM mytable
WHERE REPLACE (Col, 'a', '') = 'bbb'
But after I upgraded phpMyAdmin to version 4.5.4.1, it got below errors at WHERE clause near REPLACE.
This error can reproduce any database with any table.
If I change the query to below, it is working.
SELECT *
FROM mytable
WHERE (REPLACE (Col, 'a', '')) = 'bbb'
Is it the bug of phpMyAdmin? OR MySQL plan to change its syntax not to support without parentheses?
This appears to have been a bug with the parser library used by phpMyAdmin. I've opened a bug report at https://github.com/phpmyadmin/sql-parser/issues/43 but it seems to have been already fixed; for instance I'm not able to reproduce it inversion 4.5.5.1. I suggest you upgrade your phpMyAdmin.
try this, means your 2nd options
SELECT *
FROM mytable
WHERE (REPLACE (Col, 'a', '')) = 'bbb'
and its also working(in 4.4.6) without round brackets,
Edited
but I just tested in 4.5 & 4.6, seems round brackets are must, as per new standards
Related
I've updated my coldfusion 2018 server with most recent update12 by Adobe. As soon as I've updated the server I've wrote some QoQ for my application with ORDER BY in my QoQ. Whenever I use order by in QoQ then the result data have some duplicate columns.
For my simple sample query as example,
<cfquery name="testRead" datasource="testmssql">
SELECT * FROM loginDetails
</cfquery>
<cfdump var="#testRead#" label="Main Query">
<cfquery name='readSub' dbtype="query">
SELECT userID, Username FROM testRead
ORDER BY userid DESC
</cfquery>
<cfdump var="#readSub#" label="QoQ Result" abort="true">
**Output:** Refer my image please.
Here you can see the second QoQ dump have two userID column. I'm not sure why we are having it here & where it's come from. ? If I add one more column in ORDER BY list then that column also get duplicated in result query. For example, If add ORDER BY userid DESC, userName then the query dump query having userID,userid,userName,username.
Note : It's not happening before my update12. And it's not happening for main query.
Any thoughts ? Please share. Thank you advance !.
This is a known issue with the update and a bug has been filed with Adobe. I would recommend you add a comment and vote for the bug.
Adobe Bug Tracker - CF-4212383
Duplicate columns with the same name in a Query of Queries which contains an ORDER BY clause.
Description from that bug:
Problem Description:
After applying CF 2021 Update 2, when using an ORDER BY clause in a QoQ, the fields in the ORDER BY clause have become case sensitive, and if they don't match exactly the case of the fields in the SELECT list, then a duplicate column is added to the resultant query, resulting in a query that has two (or more) columns with the same name.
Further, if no fields are added to the SELECT list and * is used instead, the fields in the ORDER BY clause must be upper case, otherwise duplicate columns with the same name (but different case) again appear in the resultant query.
This showstopping behaviour has been introduced in CF 2021 Update 2. CF2021 Update 1 behaves as expected. (CF2016 also behaves as expected).
Even though the bug mentions CF 2021 Update 2, it also affects CF 2018 Update 12. As verified by bug CF-4212430 submitted for CF 2018 Update 12 which was closed as a duplicate of the CF 2021 bug.
Firstly, I have a table in SQLlite3 with two fields CAR (TEXT NOT NULL), checkout (TEXT NOT NULL)
car checkout
red %d%d/%m%m/%Y (for example 27/09/2021)
Second, I wrote a script which the structure is when I run it, all the entries that current date is equal or bigger than checkout to be deleted.
Third, in the same script with SELECT to check if the car is in the list and checkout is bigger than current date exclude from my available cars.
The code snippet makes the first step is the following:
try:
con = lite.connect(DB)
with con:
paper=[]
cur=con.cursor()
cur.execute("DELETE FROM CHECK_TABLE WHERE DATE(substr(checkout,7,4)||substr(checkout,4,2)||substr(checkout,1,2))<=DATE(strftime('%Y%m%d',date('now')))")
con.commit()
print('Entries with old dates deleted.')
except lite.Error as e:
print('Error connection: ',e)
The problem is that is not deleting anything. The strange behaviour is firstly that the SQL query works in DB Browser,
Image: Proof DB Browser in Windows 10 - Python2.7 - SQLite3
the second strange behaviour is that no error is raising and the third strange is that I tested two days ago and it worked normally! I really need your thoughts.
The same logic is in the following code snippet which is the the third step that I described above with SELECT command.
def ReadDateAndCar(car):
try:
con = lite.connect(DB)
with con:
paper=[]
cur=con.cursor()
cur.execute("SELECT DISTINCT car FROM CHECK_TABLE WHERE car='"+car+"' AND DATE(substr(checkout,7,4)||substr(checkout,4,2)||substr(checkout,1,2))<=DATE(strftime('%Y%m%d',date('now')))")
free_cars=cur.fetchall()
return free_cars
except lite.Error as e:
print('Error connection: ',e)
return 0
Exactly the same problems. SQL query works fine, no python error is raising, it worked few days ago. Can someone enlighten me?
Both your queries are wrong and they don't work in DB Browser either.
What you should do is store the dates with the ISO format YYYY-MM-DD, because this is the only text date format compatible with SQLite's datetime functions like date() and strftime() and it is comparable.
If you use any other format the result of these functions is null and this is what happens in your case.
The expressions substr(checkout,7,4)||substr(checkout,4,2)||substr(checkout,1,2) and strftime('%Y%m%d',date('now')) return dates in the format YYYYMMDD and if you use them inside date() or strftime() the result is null.
Since you obtain in both sides of the inequality dates in the format YYYYMMDD then they are directly comparable and you should not use the function date().
The condition should be:
substr(checkout, -4) || substr(checkout, 4, 2) || substr(checkout, 1, 2) <= strftime('%Y%m%d', 'now')
When using some RE to filter rows on gin-indexed column with pg_trm, count(*) could give a wrong result (zero instead of real count):
CREATE EXTENSION pg_trgm;
CREATE TABLE t (
s text
);
CREATE INDEX ON t USING gin (s gin_trgm_ops);
INSERT INTO t VALUES ('12-34');
SET enable_seqscan = OFF; -- to force using the index on our small table
SELECT count(*) FROM t WHERE s~'\d{2}[-]?\d{2}'; -- gives me 0
But if we will turn on seq scans, we will get the correct result:
SET enable_seqscan = ON;
SELECT count(*) FROM t WHERE s~'\d{2}[-]?\d{2}'; -- gives me 1
I believe this is a bug, but to report it, I should try all this on the latest PostgreSQL version (mine is 9.5.4) but for some reasons I cannot do this. So, can anybody with a latest PG confirm this wrong behavior?
PS or maybe it's not a bug and there is something wrong with my brain/hands))
In the end it turned out that it was really a bug.
Don't know the final status, but as I understand, the fix has been committed:
https://github.com/michaelpq/postgres/commit/9e43e8714c9e976e41b7429fa7c426c9a6e5e8e6
I want to recognize TIMESTAMP in PostgreSQL by using regexp:
SELECT substring('13:14:00', '([0-1][0-9]|2[0-3]):[0-5]\d:[0-5]\d')
This query returns 13, but I need to receive result 13:14:00.
Analogical query SELECT substring('134', '1(2|3)4') returns 3 instead of 134.
So, what is the problem? My psql version is 9.3.1.
Add parenthesis:
SELECT substring('13:14:00', '(([0-1][0-9]|2[0-3]):[0-5]\d:[0-5]\d)');
The db is PostgreSQL. When I try to execute a query with parameters, such as this one
cursor.execute("""
SELECT u.username, up.description,
ts_rank_cd(to_tsvector(coalesce(username,'')|| coalesce(description,'')) , to_tsquery('%s')) as rank
FROM auth_user u INNER JOIN pm_core_userprofile up on u.id = up.user_id
WHERE to_tsvector(coalesce(username,'')|| coalesce(description,'')) ## to_tsquery('%s')
ORDER BY rank DESC;
""", ["hello","hello"])
Django complains of a ProgrammingError, adding syntax error at or near the parameter (in this example, "hello"). Here's the part of the Django generated SQL statement that the error comes from:
to_tsquery('E'hello'')
Even if I copy-paste it to a postgreSQL shell, I get the syntax error. If I omit the 'E' part, it works. What should I make of it?
ozgur,
Try
to_tsquery(%s)
instead of
to_tsquery('%s')
I believe you are missing a ' after the E.