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')
Related
I am using a h2 database to run my tests and i need to insert some default values in the database prior to testing. I'm trying to write an sql script for this however, i am having an issue inserting a uuid as a value into the relevant table.
I tried inserting the uuid as follows; insert into user_profile_table (profile_id, user_id) values (1, 'c80d54d3-500d-4539-9479-8e8961477193'); however i get an JdbcSQLDataException error stating: Value too long for column.
I assumed this is because the user_id column type is BINARY(16) so i decided to try the following query insert into user_profile_table (profile_id, userkeycloak_id) values (1, UNHEX(REPLACE('c80d54d3-500d-4539-9479-8e8961477193', '-',''))); however, then i get an error stating: JdbcSQLSyntaxErrorException: Function "UNHEX" not found; SQL statement. I read online that the h2 DB does not support the unhex function. I tried to look for others means of converting the the uuid to a format compatible with the h2 database but havent had any luck finding a viable solution.
Hence, my question is: is there any query i can use to insert the uuid (in a BINARY(16)) format into the h2 db table? Any suggestions would be highly appreciated.
To insert a UUID value into BINARY(16) column you can use standard binary string literals in both MySQL and H2:
insert into user_profile_table (profile_id, user_id)
values (1, X'c80d54d3500d453994798e8961477193');
try this solution by microsoft : https://learn.microsoft.com/en-us/sql/t-sql/data-types/uniqueidentifier-transact-sql?view=sql-server-ver16
Working with embedded database derby version 10.12.1.1.
I have created a sequence successfully as below
CREATE SEQUENCE BUCKET_SEQ AS BIGINT START WITH 1000;
But when trying to get next value using
SELECT NEXT VALUE FOR BUCKET_SEQ
below error encountered:
Syntax error: Encountered "<EOF>" at line 1, column 40.
Please suggest any pointers.
You have to SELECT from something, and the something has to be some sort of a table.
The simplest thing to do is to use the SQL VALUES keyword, which makes an (unnamed, temporary) table for you.
You then give the table a name, and the table's column a name, and select the value from that:
select t from ( values next value for bucket_seq ) s( t);
T
--------------------
1000
There are other syntax forms possible, but this is a simple one that you can use.
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.
I need to insert some data into a table in Oracle.
The only problem is one of the fields is a timestamp(6) type and it is required data. I don't care about what actually goes in here I just need to get the right syntax for an entry so that the database will accept it.
I'm using the gui web client to enter data however I don't mind using raw SQL if I have to.
Thanks.
I dunno if this helps at all, but in SQL*Plus I did this:
create table x ( a timestamp(6));
insert into x values ( current_timestamp );
select * from x;
getting me this:
T
---------------------------------------------------------------------------
15-OCT-08 02.01.25.604309 PM
So it looks like that works.
If you need to put a previously-known value into the column, how about the TO_TIMESTAMP() function? Something like this:
select to_timestamp('27/02/2002 15:51.12.539880', 'dd/mm/yyyy hh24:mi.ss.ff')
from dual ;
using to_timestamp() is one option.
the other is doing this:
INSERT INTO table VALUES (timestamp'2009-09-09 09:30:25 CET');
Here are a couple of different TO_TIMESTAMP functions that worked for me...
This TO_TIMESTAMP function worked on an INSERT against a column of type TIMESTAMP(6):
TO_TIMESTAMP('04/14/2015 2:25:55','mm/dd/yyyy hh24:mi.ss.ff')
This TO_TIMESTAMP function worked on an INSERT against a column of type DATE:
TO_TIMESTAMP('04/15/2015','mm/dd/yyyy')
insert into x values(to_timestamp('22:20:00','hh24:mi'));