Create Table DECIMAL Error - mysql

I am working with a Raspberry PI running Raspbian. I've gotten to the point where I'm setting up a MySql database and I am trying to create a DECIMAL table.
I'm following this guide.
This is the code i'm using
Use Monitoring;
create table TempHumid (ComputerTime INTEGER UNSIGNED);
#This one created the table, but it was a different type.
create table Temperature (DECIMAL(5,1);
create table Humidity (DECIMAL(5,1);
This is the error that it gives me.
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 'DECIMAL (5,1))' at line 1
I tried looking around on Google and on here, but those solutions didn't seem to work. I'm fairly new to the PI, so it may just be user error.

You should specify your columns. See below:
CREATE TABLE Temperature (
Temperature DECIMAL(5,1)
);
CREATE TABLE Humidity (
Humidity DECIMAL(5,1)
);

Related

Issue with MySQL Generated Columns

Hello I am trying to make a alter an exsisting table to add a Generated columns which is the count of all the rows in another table(It will be a like system so I am going to do all the matching and "WHERE" once I get this to work)
I am currently using this.
ALTER TABLE board ADD like_cnt INT GENERATED ALWAYS AS (COUNT(*) FROM likes) NOT NULL;
But it gives me 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 'FROM likes) NOT NULL' at line 1
I am using WAMP and it has SQL version 5.7.24
Is this not possible or am I doing something wrong ?
There are limits in GENERATED COLUMNS notably 'Subqueries are not permitted'

Asigning 2 integer values to a single item in a table in MySQL?

I have this line in an SQL table:
Income NUMBER(12,2),
And I want to recreate the table in mysql, but it's throwing me this error:
error 1064 (42000): You have an error in your SQL syntax; check the manual to use near '2))' at line 4
This is how I'm creating the table:
CREATE TABLE Doctors(
DoctorId INTEGER(5) PRIMARY KEY,
DoctorName VARCHAR(20),
Income INTEGER(12,2));
How can I do this in mysql?
*I have been able to replicate the table in sqlite without errors.
If you are trying to do what your question title states (i.e. store two integer values into the same column), you may be looking to use an array. Databases like PostgreSQL support arrays (see PostgreSQL array documentation), but MySQL doesn't do so natively (see MySQL Documentation). However, the MySQL documentation suggests using a language extension to serialise/deserialise the data (see PHP example).
Otherwise, it may be that you are simply looking for a DECIMAL type:
Income DECIMAL(12,2)
See MySQL Documentation for fixed-point types

Sphider MySQL Tables

I'm trying to install Sphider to search my site and when I try to create the MySQL tables I am getting this error:
create table query_log (
query varchar(255),
time timestamp(14),
elapsed float(2),
results int,
key query_key(query)
) ENGINE = MYISAM;
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 '(14),
elapsed float(2),
results int,
key query_key(query)
) ENGINE = MYI' at line 3
How do I get round this?
According to the Sphider forums, it looks like this is an issue with the TimeStamp field type, or at least the way it's used in this CREATE TABLE query. (http://www.sphider.eu/forum/read.php?2,8933). On that forum page it is suggested that you:
1) editing the admin/install.php file,
2) Changing line 139,
FROM:
time timestamp(14),
TO
time timestamp,
There is no such thing as a timestamp(14).
The code should just be:
time timestamp;
Remove the (14)
Where the heck did you get that from, that they wouldn't understand basic mysql syntax?

MySQL Truncate Table Before Insert

I am creating a table in MySQL for which I only ever want it to contain one tuple at a time. To enforce this, I am trying to create a trigger which will truncate the table each time an INSERT occurs. However, I am running into problems.
SQL:
CREATE TRIGGER `tbl_hire_truncate`
BEFORE INSERT ON `tbl_hire`
FOR EACH ROW
BEGIN
TRUNCATE TABLE `tbl_hire`;
END
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 '' at line 5
Every example of a trigger that I've seen uses a FOR EACH loop, but it certainly doesn't make much sense with what I am trying to achieve.
How can I rewrite my SQL to achieve my goal?

#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 '(14),

Creating a search engine for my website with the help of Sphider
but when creating the MySQL database tables the following error message showed
Error
SQL query:
create table query_log (
query varchar(255),
time timestamp(14),
elapsed float(2),
results int)
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 '(14),
elapsed float(2),
results int)' at line 3
The problem lies with the number following your timestamp declaration. MySQL documentation says of the timestamp type:
the display width is fixed at 19 characters, and the format is 'YYYY-MM-DD HH:MM:SS'.
So, your code can be fixed by making the following modification:
create table query_log (
query varchar(255),
time timestamp,
elapsed float(2),
results int
)
As far as the number "14" goes, it's unclear where you were going with that. Does the project you are working on require that a timestamp of a specific length? If so, it might be best to use another data type, or to convert the timestamp to the desired format after it is pulled from the database.
I am new on StackExchange, so I hope that I've adequately answered the question. Please let me know if I can help with anything else!