Vertica database sql operation memo

http://itindex.net/detail/36350-vertica-%E6%95%B0%E6%8D%AE%E5%BA%93-sql
delete the primary key (the primary key value of the Vertica database is not unique):
SELECT ANALYZE_CONSTRAINTS('fb_s.c_log');

Find the key name, then:

ALTER TABLE fb_s.c_log DROP CONSTRAINT C_PRIMARY;

SELECT ANALYZE_CONSTRAINTS('fb_s.user_info');

ALTER TABLE fb_s.user_info DROP CONSTRAINT C_PRIMARY;

Create user and SCHEMA:

CREATE user fb_s_sql IDENTIFIED BY 'password';
CREATE SCHEMA fb_s_sql;

Give permission: GRANT
ALL ON SCHEMA fb_s_sql TO fb_s_sql;
GRANT ALL ON SCHEMA fb_s TO     fb_s_sql

; int NOT NULL,     cash int,






    gold int,
    level int,
    rtime datetime,
    tid varchar(20),
    act varchar(50),
    item varchar(500),
    value int,
    value2 int,
    time datetime
);

CREATE TABLE fb_s.new_c_log (
  uid integer PRIMARY KEY NOT NULL,
  cash integer,
  gold integer,
  level integer,
  rtime datetime,
  tid varchar(20),
  act varchar(50),
  item varchar(500),
  value integer,
  value2 integer,
  time datetime NOT NULL
)
PARTITION BY EXTRACT(year FROM time)*100 + EXTRACT(month FROM time);

后一个是按time字段分区

Add and modify fields:

ALTER TABLE fb_s.c_logADD COLUMN value2 integer default 0;
ALTER TABLE fb_s.c_log ALTER COLUMN duration SET DEFAULT 0;
ALTER TABLE fb_s.c_log ALTER COLUMN mesg SET DEFAULT '';


import data between two tables:
insert into fb_s.c_log (uid,cash,gold,level,rtime,tid,act,item,value,value2,time)
(select * from fb_s.c_logbak); Import

data between the two libraries:

export in the source library:

vsql -d topcity -U dbadmin -w password -F ',' -At -o fs_user_info.csv -c "SELECT * FROM fb_s.user_info;" &
vsql -d topcity -U dbadmin -w password -F ',' -At -o fs_c_log.csv -c "SELECT * FROM fb_s.c_log;" &

Destination library import:
COPY fb_s.user_info FROM '/opt/fs_user_info.csv' EXCEPTIONS '/tmp/exp.log' DELIMITER ',';
COPY fb_s.c_log  FROM '/opt/fs_c_log.csv' EXCEPTIONS '/tmp/exp.log' DELIMITER ',';

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326728346&siteId=291194637