I got one way to use copy command to insert in vertica if the file is in client system(i.e no need to put it in vertica linux system).
It is done using verticacopystream.
Below is the C# code to Do this and I think like me it will help someone. It works for me using vertica 6.1
Thanks
Ajit
Code: Select all
VerticaConnection conn = new VerticaConnection("SERVER=<SERVER>;DATABASE=<DB>;PORT=5433;USER=<USER>;PASSWORD=<PWD>");
conn.Open();
try
{
using (conn)
{
VerticaTransaction txn = conn.BeginTransaction();
string input = @"<FIle Path>";
FileStream inputfile = File.OpenRead(input);
string copy = @"COPY <table> FROM STDIN RECORD TERMINATOR E'\r\n' DELIMITER E'\t' ENFORCELENGTH NO COMMIT";
VerticaCopyStream stream = new VerticaCopyStream(conn, copy);
stream.Start();
stream.AddStream(inputfile, false);
stream.Execute();
long rowsInserted = stream.Finish();
IList<long> rowsRejected = stream.Rejects;
Console.WriteLine(" Rows inserted: " + rowsInserted);
Console.WriteLine(" Rows rejected: " + rowsRejected.Count);
txn.Commit();
}
}
catch(Exception)
{
}