multi-row Inserts and timestamps
I'm trying to do a multi-row insert here.
My situation looks like:
My situation looks like:
CREATE TABLE tablename (When I run an insert as so, it works fine:
col1 VARCHAR(10) NOT NULL,
col2 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)
INSERT INTO tablename ( col1, col2 )When I try and do a multi-row insert:
SELECT 'value1','2014-03-06T21:05:00.000000000-00:00';
INSERT INTO tablename ( col1, col2 )I get:
SELECT 'value1','2014-03-06T21:05:00.000000000-00:00'
UNION ALL
SELECT 'value2','2014-03-06T21:05:00.000000000-00:00';
ERROR 2631: Column "col2" is of type timestamp but expression is of type varcharI have no idea what is going on. Some help would be greatly appreciated. It seems to work just fine unless there is a timestamp involved. What's going on?
0
Comments
INSERT INTO tablename ( col1, col2 )
SELECT 'value1','2014-03-06T21:05:00.000000000-00:00'::timestamp
UNION ALL
SELECT 'value2','2014-03-06T21:05:00.000000000-00:00'::timestamp;
INSERT INTO tablename ( col1, col2 )
select c1, c2::timestamp from (
SELECT 'value1' as c1,'2014-03-06T21:05:00.000000000-00:00' as c2
UNION ALL
SELECT 'value2' as c1,'2014-03-06T21:05:00.000000000-00:00' as c2
) q;
Another alternative -- if this is JDBC, just prepare a regular INSERT .. VALUES statement, then execute it twice in a row.
Vertica will internally/automatically rewrite this as a single statement.
To be clear, you are saying that: Will not result in two different transactions, but will do it all in one?
To be clear, you are saying that: Will not result in two different transactions, but will do it all in one?
To be clear, you are saying that: Will not result in two different transactions, but will do it all in one?
There are a bunch of specifics -- take a look at this bit of documentation:
https://my.vertica.com/docs/7.0.x/HTML/index.htm#Authoring/ProgrammersGuide/ClientJDBC/BatchInsertsU...
My attempt: Another attempt:
INSERT INTO tablename ( col1, col2 ) VALUES (?,?);
then run that prepared statement twice from Java.
The documentation link above has some example Java code; take a look there to see what I'm talking about.
If you really want to do this with a single Java function call, then something like Sharon's approach is probably the way to go. This INSERT mechanism is intended for if you want to stream a large (potentially variable) number of values into a table quickly.
- can one record be inserted with a timestamp field
- can multiple records be inserted without a timestamp field
- cant multiple records be inserted with a timestamp field?
Is this a bug? Is this documented anywhere? Is it an inference thing?Why does this happen? And this is fine? And so is this (no timestamp field)?