Clickhouse ALTER MATERIALIZE COLUMN is not available - clickhouse

SELECT version()
21.3.10.1
ALTER TABLE tmp MATERIALIZE COLUMN s
Expected one of: INDEX, TTL
Why?

https://github.com/ClickHouse/ClickHouse/blob/master/docs/en/whats-new/changelog/2021.md#clickhouse-release-v2110-2021-10-16
ClickHouse release v21.10, 2021-10-16
...
Add ALTER TABLE ... MATERIALIZE COLUMN query. #27038 (Vladimir Chebotarev).

Related

Using multiple select statement inside insert statement in Hive

I'm new in Hive. I have three tables like this:
table1:
id;value
1;val1
2;val2
3;val3
table2
num;desc;refVal
1;desc;0
2;descd;0
3;desc;0
I want to create a new table3 that contains:
num;desc;refVal
1;desc;3
2;descd;3
3;desc;3
Where num and desc are columns from table2 and refVal is the max value of column id in table1
Can someone guide me to solve this?
First, you have to create an table to hold this.
CREATE TABLE my_new_table;
After that, you have to insert into this table, as showed here
INSERT INTO TABLE my_new_table
[PARTITION (partcol1=val1, partcol2=val2 ...)]
select_statement1;
In the select_statement1 you can use the same select you would normally use to join and select the columns you need.
For more informations, you can check here

Convert Raw SQL Query to Laravel Eloquent ALTER TABLE DROP INDEX

can anyone help me turn the query in to Eloquent?
ALTER TABLE `invoices` DROP INDEX
`invoices_erp_id_origin_customer_id_unique`, ADD UNIQUE
`invoices_erp_id_origin_customer_id_unique`
(`erp_id`, `origin`, `customer_id`, `podtyp`)
Try this, eloquent only manipulates objects, to alter table use DB facade :)
DB::statement('ALTER TABLE `invoices` DROP INDEX
`invoices_erp_id_origin_customer_id_unique`, ADD UNIQUE
`invoices_erp_id_origin_customer_id_unique`
(`erp_id`, `origin`, `customer_id`, `podtyp`)');

Altering data type and default on DB2 LUW 10.5

I am trying to do 2 alters to a column in DB2 in the same alter command, and it doesn't seem to like my syntax. Is there a way to do this? If so, how?
create table tbl(col varchar(10))
The following works, using 2 alter statements:
alter table tbl
alter column col set data type varchar(128)
alter table tbl
alter column col set default current user
The following attempts fail:
alter table tbl
alter column col set data type varchar(128) set default current user
An unexpected token "set data type varchar(128)" was found following
"TBL alter column col". Expected tokens may include: ""..
SQLCODE=-104, SQLSTATE=42601, DRIVER=3.67.28
alter table tbl
alter column col set data type varchar(128) with default current user
An unexpected token "data type varchar(128)" was found following
"alter column col set". Expected tokens may include: ""..
SQLCODE=-104, SQLSTATE=42601, DRIVER=3.67.28
alter table tbl
alter column col set data type varchar(128)
alter column col set default current user
"COL" is a duplicate name.. SQLCODE=-612, SQLSTATE=42711,
DRIVER=3.67.28
You cannot alter the same column twice in the same statement -- that's what SQLCODE -612 is telling you. As per http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.messages.sql.doc/doc/msql00612n.html
a column name can only be referenced in one ADD, DROP COLUMN, or ALTER COLUMN clause in a single ALTER TABLE statement.
The other attempts are syntactically incorrect.
alter table tbl
alter COLUMN col set DATA TYPE VARCHAR(128)
ALTER column B SET DEFAULT current user;

How to insert init-data into a table in hive?

I wanted to insert some initial data into the table in hive, so I created below HQL,
INSERT OVERWRITE TABLE table PARTITION(dt='2014-06-26') SELECT 'key_sum' as key, '0' as value;
but it does not work.
There is another query like the above,
INSERT OVERWRITE TABLE table PARTITION(dt='2014-06-26') SELECT 'key_sum' as key, '0' as value FROM table limit 1;
But it also didn't work, as I see that the tables are empty.
How can I set the initial data into the table?
(There is the reason why I have to do self-join)
About first HQL it should have from clause, its missing so HQL failure,
INSERT OVERWRITE TABLE table PARTITION(dt='2014-06-26') SELECT 'key_sum' as key, '0' as value;
Regarding second HQL, from table should have atleast one row, so it can set the constant init values into your newly created table.
INSERT OVERWRITE TABLE table PARTITION(dt='2014-06-26') SELECT 'key_sum', '0' FROM table limit 1;
you can use any old hive table having data into it, and give a hit.
The following query works fine if we have already test table created in hive.
INSERT OVERWRITE TABLE test PARTITION(dt='2014-06-26') SELECT 'key_sum' as key, '0' as value FROM test;
I think the table which we perform insert should be created first.

How to set default value for column of new created table from select statement in 11g

I create a table in Oracle 11g with the default value for one of the columns. Syntax is:
create table xyz(emp number,ename varchar2(100),salary number default 0);
This created successfully. For some reasons I need to create another table with same old table structure and data. So I created a new table with name abc as
create table abc as select * from xyz.
Here "abc" created successfully with same structure and data as old table xyz. But for the column "salary" in old table "xyz" default value was set to "0". But in the newly created table "abc" the default value is not set.
This is all in Oracle 11g. Please tell me the reason why the default value was not set and how we can set this using select statement.
You can specify the constraints and defaults in a CREATE TABLE AS SELECT, but the syntax is as follows
create table t1 (id number default 1 not null);
insert into t1 (id) values (2);
create table t2 (id default 1 not null)
as select * from t1;
That is, it won't inherit the constraints from the source table/select. Only the data type (length/precision/scale) is determined by the select.
The reason is that CTAS (Create table as select) does not copy any metadata from the source to the target table, namely
no primary key
no foreign keys
no grants
no indexes
...
To achieve what you want, I'd either
use dbms_metadata.get_ddl to get the complete table structure, replace the table name with the new name, execute this statement, and do an INSERT afterward to copy the data
or keep using CTAS, extract the not null constraints for the source table from user_constraints and add them to the target table afterwards
You will need to alter table abc modify (salary default 0);
new table inherits only "not null" constraint and no other constraint.
Thus you can alter the table after creating it with "create table as" command
or you can define all constraint that you need by following the
create table t1 (id number default 1 not null);
insert into t1 (id) values (2);
create table t2 as select * from t1;
This will create table t2 with not null constraint.
But for some other constraint except "not null" you should use the following syntax
create table t1 (id number default 1 unique);
insert into t1 (id) values (2);
create table t2 (id default 1 unique)
as select * from t1;

Resources