I am trying to add some data to a PostgreSQL table using INSERT TO on pgAdmin4.
This is the code that I am trying to run;
INSERT INTO raw(id,object_id, confidence, timestamp)
VALUES (1,9.0,0.012145853244069600,2020-05-20 13:02:52.281964)
And I am getting the following response;
ERROR: syntax error at or near "13"
I am quite new to SQL and PostgreSQL, so go easy on me. I assume that it is something wrong with handling time related data.
Use single quotes:
INSERT INTO raw(id,object_id, confidence, timestamp)
VALUES (1,9.0,0.012145853244069600,'2020-05-20 13:02:52.281964')
I am trying to insert a date inside the orderDate column in my sql database, which is of datatype date
date = (start_date.strftime("%Y-%m-%d"))
testData.cur.execute("INSERT INTO customerOrders (orderDate) VALUES %s", (date,))
testData.cn.commit()
Here is the value of the variable 'data':
2019-01-01
Here is the data type of the date:
class 'str'
I am subject to the error of:
mysql.connector.errors.ProgrammingError: 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 ''2019-01-01''
at line 1
Add simple quotes in %s. MySQL needs to know that '2019-01-01' is a date type input.
INSERT INTO customerOrders (orderDate) VALUES '%s'
Consider parameterization of exact date time variable and avoid string formatting. Also, in SQL, VALUES clause requires parentheses enclosure around numbers or literals:
testData.cur.execute("INSERT INTO customerOrders (orderDate) VALUES (%s)",
(start_date,))
testData.cn.commit()
I have a table called project-users and want to write a SQL query like SELECT * FROM project-users I get this error ERROR: syntax error at or near "-".
I cannot change the table name at this point.
According to http://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html, you should use double quotes.
In your case, for PostgreSQL the query should be:
SELECT * FROM "project-users";
It is good practice to avoid the use of characters that need escaping or that contain spaces in identifiers.
I am using Oracle SQL and have just altered a table and added a column named Date_Employed
ALTER TABLE Employees ADD Date_Employed date;
My problem is that whenever I try to insert a value into the Date_Employed column i get an error ORA-00917: Missing comma when I type in the code below
INSERT INTO Employees(Date_Employed) VALUES (26 September 2001);
I would like to know whether the method I am using to try to input data into the column is correct? and if it is not, what is the correct way to insert date data into the column?
Also, I would like to know, why I am getting the error I described?
Use a proper date format for Oracle and enclose it in single quotes:
INSERT INTO Employees(Date_Employed)
VALUES (DATE '2001-09-26');
INSERT INTO
Employees (Date_Employed)
VALUES
(TO_DATE('2003/05/03 21:02:44', 'yyyy/mm/dd hh24:mi:ss'));
You are getting error because oracle is not able to understand the date format you have given.
I am am using sql server 2005 and doing a simple insert into and getting an incorrect syntax error. I See nothing wrong with my code Can someone give me some ideas what could be wrong with it?
insert into inonhd
(fpartno,fpartrev,flocation,fonhand,fcudrev)
Values
('CRV109','1','11','01','1'),
('CRV110','0','11','01','0')
the error is Incorrect syntax near ','.
You must add each row in separate command.
insert into inonhd
(fpartno,fpartrev,flocation,fonhand,fcudrev)
Values
('CRV109','1','11','01','1')
and:
insert into inonhd
(fpartno,fpartrev,flocation,fonhand,fcudrev)
Values
('CRV110','0','11','01','0')
It is really important to note that the syntax in the question is fine for more recent versions of SQL Server. This is acceptable:
insert into inonhd(fpartno, fpartrev, flocation, fonhand, fcudrev)
Values ('CRV109','1','11','01','1'),
('CRV110','0','11','01','0');
If you want to do this in one statement, you can use select . . . union all:
insert into inonhd(fpartno, fpartrev, flocation, fonhand, fcudrev)
select 'CRV109','1','11','01','1' union all
select 'CRV110','0','11','01','0';
Of course, multiple inserts are another possibility.