Strange syntax error in simple CREATE TABLE command - PostgreSQL, MySQL, & SQLite - mysql

I am getting a syntax error with PostgreSQL, MySQL, & SQLite that I don't understand. It occurs when the same CREATE TABLE command is run from Python and as a Query in pgAdmin4 and MySQL WorkBench. The same command works perfectly on SQL Server, using MS SQL Server Management Studio.
The command is:
create table asDataSpecs ( NumField1 integer, CharField1 char(30), CharField2 char(30) )
pgAdmin4 displays the error message:
LINE 1: ...e asDataSpecs ( NumField1 integer, CharField1 char(30), Char...
^
SQL state: 42601
Character: 62
MySQL generates an "Error Code: 1064" at the same point:
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 '(30), CharField2 char(30) )' at line 1
PostgreSQL & MySQL understandably fail at the same point when this command is run in Python - as a .execute() on a cursor connected to the appropriate back-end and database.
SQLite (run using .execute() in the same Python program) produces an error presumably at the same point:
Failed 'Try' while attempting to create the 'asDataSpecs' table
near "(": syntax error
Why do PostgreSQL, MySQL, & SQLite accept the "integer" field, but reject the first "char" one - yet MS SQL Server runs it OK?
(I don't think it is a credentials issue, as I successfully used ODBC with the same credentials to create other tables in the same database - in all four backends. I would expect different error messages, if credentials were the issue - and it should not accept the numeric field.)

That was it - funky hidden characters. (There was some high-ASCII character instead of a normal space (ASCII 32) between the field name and data type.)
All platforms now work as expected, both in the Python program and the respective back-end management consoles.
For anyone who is interested, even NotePad++ displayed this as a space. But basic Windows NotePad revealed the mystery.
Thanks again, "sticky bit".

Related

Why I can't use "source" in MySQL bench?

I am at the very beginning of mysql, trying to insert data into a new schema called crashcourse.
My code is:
use crashcourse;
source /Users/chenxinyu/Downloads/mysql_scripts/create.sql ;
source /Users/chenxinyu/Downloads/mysql_scripts/populate.sql ;
But it turns out that "11:35:24 source /Users/chenxinyu/Downloads/mysql_scripts/create.sql 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 'source /Users/chenxinyu/Downloads/mysql_scripts/create.sql' at line 1 0.00031 sec", so how can I solve this problem?
There are a number of commands, including source, that are only recognized by the MySQL command-line client. See https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html
These commands are parsed and handled by that client, and are not sent to the MySQL Server. This makes them different from all other SQL statements, which are sent to the server to be parsed and executed.
Other clients, such as MySQL Workbench, phpmyadmin, and other developer tools, would need to implement support for those special client-side commands themselves. Few of them do.
Likewise when you write code to use the MySQL API in your own applications, unless you pre-check the SQL statement and handle the special client-only commands yourself, they are not supported.

Error code: 1064 in MySQL when create SOURCE?

I want to use my SQL'book_data2' file from the desktop E drive as a 'SOURCE'. But I am getting an error code 1064 in MySQL workbench. Could you help me for that issue? I am giving the code and action output below.
Code:
SOURCE E:\DataPractice\Practice\book_data2.sql;
Action Output:
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 'SOURCE E:\DataPractice\Practice\book_data2.sql' at
line 1 0.000 sec
There are a number of commands that are supported by the mysql client (that is, the command-line client, not MySQL Workbench), but they are parsed in the client, not sent to the server as SQL statements. The MySQL Server does not recognize these commands.
It can be confusing, but remember both the client and the server may process commands. You just have to read the documentation to learn which commands are in the list of client-only commands:
https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html
(Except USE, which is recognized by both mysql client and server, just to make sure there's an exception to every rule!)
If you want to use MySQL Workbench to "source" an SQL file, in other words load a file, read the SQL commands in that file, and execute them, Workbench does support this action, but they call it Data Import/Restore. It's documented here: https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-management.html

'Syntax Error' when using Database Navigator for PyCharm

I have a project with a MySQL database to which I connected using the Database Navigator plugin.
Now when I open the DB Browser window, select the database and click on "Open DB console" and insert the query
SELECT CAST('2017-08-29' AS DATE);
for one, the IDE highlights CAST as an unknown identifier:
and, additionally, when I try to execute the statement, I get the error
Error executing SELECT statement. 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 1 - Connection: test: 112ms
However, to my knowledge, this is valid MySQL, at least this page suggests so.
I am also able to perform MySQL queries with casts from a python script that builds the connection itself.
What am I doing wrong here? Do I have to configure the dialect for Database Navigator?

Unable to import tables from MySQL

I need to import few tables from MySQL to MSSQL. Below are the steps I followed in SSIS
1). Open the SQL Server Import/Export Wizard.
2). Source connections defined as per the MySQL ODBC Connector.
3). Destination defined as per MSSQL SQL authentication.
now when i try to run the package, i get the following error
"you have an error in your sql syntax; check the manual that corresponds right syntax"
On digging deep into the issue, i found that it is trying to fetch items using a query
Select * from "table"
How do i avoid double quotes? I know it is something to do with ANSI_QUOTES, but how do I set ANSI_QUOTES property
In the file ProgramData\MySQL\MySQL Server 5.6\my.ini edit the "sql-mode" property.
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES"
^

How download DB MySQL on hosting?

This first that I try to download DB MySQL on "godaddy", but I receive this message:
Error
There is a chance that you may have found a bug in the SQL parser. Please examine your query closely, and check that the quotes are correct and not mis-matched. Other possible failure causes may be that you are uploading a file with binary outside of a quoted text area. You can also try your query on the MySQL command line interface. The MySQL server error output below, if there is any, may also help you in diagnosing the problem. If you still have problems or if the parser fails where the command line interface succeeds, please reduce your SQL query input to the single query that causes problems, and submit a bug report with the data chunk in the CUT section below:
----BEGIN CUT----
eNrt2c1OwkAUBeBDAQODiSyI67tgYwKlLYLQlRXLXwrUFnFpTERDJIUYMfI6PoHv4HtRp01Al26M
Jt4vM5mb07kzyWxre97IM6mlU8sgxx6apJFOjbrWFP5YftgI4U9kWuzdFsVg7V84JtVUTW3Wy/PF
vbj0PRr5JbI69nBcooktW65mAflW2/J68c5a9US4A8skQ9X1aFSF23WjraWRHx2mq3VyZsHqRTjW
sGPSNCivnu7KDRFftkmI/SSQTwCaXNDFjpJBFkhHZWab5eV8ewfENqhUAAJjjDHGGGOMMcb+OgXh
D5y6h14QLM7P+H0ZY4wxxhhjjLHf9pqI/+n/Wwko6KMtqy4Od6m7q/tIKkrhiL4JKWSXj4vl9cN0
jTRycf18M19NkcoahrwOOJXzIAOkc4UCjr8E4bYz/GwL8QHyNkoe
----END CUT----
----BEGIN RAW----
ERROR: C1 C2 LEN: 0 1 8609
STR: �
SVN: $Id$
MySQL: 5.0.96-log
USR OS, AGENT, VER: Win SAFARI 5.0.537
PMA: 2.11.11.3
PHP VER,OS: 5.1.6 Linux
LANG: en-utf-8
SQL: �
0H ��
// �InnoDB�JFHPJ) prop_keyprop_value 22#4#�prop_key�prop_value�
----END RAW----
SQL query:
� 0H �� // �InnoDB�JFHPJ) prop_keyprop_value 22#4#�prop_key�prop_value�
MySQL said: Documentation
#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 'þ
' at line 1
What did wrong I do? I thing this is because version of MySQL, I changed from 5.6 to 5.0.96 and created new table, but receive same result.