Skip to main content

How to add a virtual column ?

  • May 31, 2014
  • 6 replies
  • 25 views

H2O
  • New Participant
I need to make something like an auto increment pk in a new table i am about to load into Vertica.
But i dont have that data into my csv file !
How can i do this ?

6 replies

Adrian_Oprea_1
Forum|alt.badge.img+1
  • Participating Frequently
  • May 31, 2014
What you need is a sequence here that will generate that auto increment pk ! 
-make sure the sequence is not used by any so the nextval should be 1 
See example :
create table bla (id int PRIMARY KEY, --virtual column
col2 ,
col3,
...
);
--create sequence
CREATE SEQUENCE seq_bla START 1;
--load the data
copy bla(
id as seg_bla.nextval,
col2,
col3,
....
) from '/csv_file' delimiter ',' direct;
This should do the trick

H2O
  • Author
  • New Participant
  • May 31, 2014
i will give it a try
Thx

H2O
  • Author
  • New Participant
  • May 31, 2014
Hi,
that worked , but i don't get all the data loaded into my table . i Mean i have millions of rows of data but not all appear in the count(*) from the loaded table.

Adrian_Oprea_1
Forum|alt.badge.img+1
  • Participating Frequently
  • May 31, 2014
If you don't specify any REJECTED DATA or EXCEPTIONS log file location then  the rejected data and the exceptions will be saved into 'catalog_dir/CopyErrorLogs/tablename-filename-of-source-copy-from-rejections' by default.<BR />  Take a look at that data and you will find why not all of your data loaded. Also read the docs on copy command for more details.


anvy_elizabeth
you can also use 
create table xyz(ID auto_increment,name varchar(2));


xyz.txt
an
bn
cn
dn

copy xyz from local 'path/xyz.txt';
select * from xyz;
1 an
2 bn
3 cn
4 dn

this may be enough


H2O
  • Author
  • New Participant
  • June 2, 2014
Thank you,solved my problem!