Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8013

Beginners • Re: mariadb: insert into error: thinks a variable in the values list is a column

$
0
0
cur.execute(" INSERT INTO data( name, value, mod_date) VALUES( 'temperature', temp_value, current_time )")

Code:

MariaDB [sensor1]> describe data;+----------+-------------+------+-----+---------+----------------+| Field    | Type        | Null | Key | Default | Extra          |+----------+-------------+------+-----+---------+----------------+| id       | int(11)     | NO   | PRI | NULL    | auto_increment || name     | varchar(50) | NO   |     | NULL    |                || value    | varchar(50) | YES  |     | NULL    |                || mod_date | date        | YES  |     | NULL    |                |+----------+-------------+------+-----+---------+----------------+
Much appreciation from this Newbe!
You can't insert a DATE into a TIME column, you can't insert a TIME into a DATE column.
So with your current definition this SQL would work

Code:

cur.execute(" INSERT INTO data( name, value, mod_date) VALUES( 'temperature', temp_value, current_date )")
You need to create the table with the correct type, or use DATETIME https://mariadb.com/kb/en/datetime/.

Statistics: Posted by DougieLawson — Fri Sep 20, 2024 9:21 pm



Viewing all articles
Browse latest Browse all 8013

Trending Articles