vertica - Create table with a variable name -


i need create tables on daily basis name date in form @ (yymmdd), tried :

dbadmin=> \set table_name 'select to_char(current_date, \'yymmdd \')' dbadmin=> :table_name;  to_char --------- 150515 (1 row) 

and tried create table table name set parameter :table_name, got this

dbadmin=> create table :table_name(col1 varchar(1)); error 4856: syntax error @ or near "select" @ character 14 line 1: create table select to_char(current_date, 'yymmdd ')(col1 va... 

is there way store value in variable , use variable table name or assign priority inner select statement has execute first give me name require.

please suggest!!!

try this

  • for ever reason variable stored comes space , had remove , cannot start naming table starting numbers had add in form tbl_
  • in short need store value of exit need work , execute query.

    \set table_name `vsql -u dbadmin -w d -t -c "select concat('tbl_',replace(to_char(current_date, 'yymmdd'),' ',''))"` 

create table:

create table :table_name(col1 varchar(1)); (dbadmin@:5433) [dbadmin] *> \d tbl_150515 schema      | public table       | tbl_150515 column      | col1 type        | varchar(1) size        | 1 default     | not null    | f primary key | f foreign key | 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -