ddl

Hive 1.1.0 Alter table partition type from int to string

浪子不回头ぞ 提交于 2019-12-01 04:43:12
I have a table which has a partition of type int but which I want to convert to string. However, I can't figure out how to do this. The table description is: Col1 timestamp Col2 string Col3 string Col4 string Part_col int # Partition information # col_name data_type comment Part_col int The partitions I have created are Part_col=0, Part_col=1, ..., Part_col=23 I want to change them to Part_col='0' etc I run this command in hive: set hive.exec.dynamic.partitions = true; Alter table tbl_name partition (Part_col=0) Part_col Part_col string; I have also tried using "partition (Part_col)" to change

Forcing Management Studio to use ALTER TABLE instead of DROP/CREATE

微笑、不失礼 提交于 2019-12-01 03:24:40
I'm wondering if is there a way to force MSSQL Management Studio to produce a script like this: ALTER TABLE Mytable ADD MyCol bit NOT NULL CONSTRAINT MyColDefault DEFAULT 0 WITH VALUES ALTER TABLE [dbo].Mytable ALTER COLUMN MyCol2 int NULL GO when I alter a very simple property of a column on a table. If I do this in the designer and ask for the produced script, the script doesn't do such simple tasks, but instead copies all the data in a tmp table, drops the original table, renames the tmp table with the original table name. And, of course, drops and recreates every constraint and

Hive 1.1.0 Alter table partition type from int to string

谁都会走 提交于 2019-12-01 02:22:05
问题 I have a table which has a partition of type int but which I want to convert to string. However, I can't figure out how to do this. The table description is: Col1 timestamp Col2 string Col3 string Col4 string Part_col int # Partition information # col_name data_type comment Part_col int The partitions I have created are Part_col=0, Part_col=1, ..., Part_col=23 I want to change them to Part_col='0' etc I run this command in hive: set hive.exec.dynamic.partitions = true; Alter table tbl_name

CREATE UNIQUE INDEX IF NOT EXISTS in postgreSQL

浪子不回头ぞ 提交于 2019-11-30 19:43:15
Plese I would like to do in PostgreSQL something like CREATE UNIQUE INDEX IF NOT EXISTS Any idea? You can check, if an index with a given name does exist by this statement. If your index name is some_table_some_field_idx SELECT count(*) > 0 FROM pg_class c WHERE c.relname = 'some_table_some_field_idx' AND c.relkind = 'i'; Starting from Postgres 9.5 you can even use CREATE INDEX IF NOT EXISTS Just another ready-to-use solution. PostgreSQL v9.0+: DO $BLOCK$ BEGIN BEGIN CREATE INDEX index_name ON table_name( column_name ); EXCEPTION WHEN duplicate_table THEN RAISE NOTICE 'index ''index_name '' on

Is there a postgres command to list/drop all materialized views?

有些话、适合烂在心里 提交于 2019-11-30 17:12:20
I am creating multiple views in my code and each time the code is run, I would like to drop all the materialized views generated thus far. Is there any command that will list all the materialized views for Postgres or drop all of them? Show all: SELECT oid::regclass::text FROM pg_class WHERE relkind = 'm'; Names are automatically double-quoted and schema-qualified where needed according to your current search_path in the cast from regclass to text . In the system catalog pg_class materialized views are tagged with relkind = 'm' . The manual: m = materialized view To drop all, you can generate

Is there a postgres command to list/drop all materialized views?

独自空忆成欢 提交于 2019-11-30 16:29:18
问题 I am creating multiple views in my code and each time the code is run, I would like to drop all the materialized views generated thus far. Is there any command that will list all the materialized views for Postgres or drop all of them? 回答1: Show all: SELECT oid::regclass::text FROM pg_class WHERE relkind = 'm'; Names are automatically double-quoted and schema-qualified where needed according to your current search_path in the cast from regclass to text . In the system catalog pg_class

Renaming multiple columns in one statement with PostgreSQL

戏子无情 提交于 2019-11-30 14:31:17
问题 Is it possible to rename multiple columns in a single statement, something along the lines of: ALTER TABLE Users RENAME COLUMN userName TO user_name, RENAME COLUMN realName TO real_name; 回答1: No. While other actions can be combined, that's not possible with RENAME . The manual: All the forms of ALTER TABLE that act on a single table, except RENAME , SET SCHEMA , ATTACH PARTITION , and DETACH PARTITION can be combined into a list of multiple alterations to be applied together. Since RENAME is

Test Column exists, Add Column, and Update Column

吃可爱长大的小学妹 提交于 2019-11-30 12:24:04
问题 I'm trying to write a SQL Server database update script. I want to test for the existence of a column in a table, then if it doesn't exist add the column with a default value, and finally update that column based on the current value of a different column in the same table. I want this script to be runnable multiple times, the first time updating the table and on subsequent runs the script should be ignored. My script currently looks like the following: IF NOT EXISTS(SELECT * FROM INFORMATION

SQL语言的分类(DQL、DML、DDL、DCL的概念与区别)

∥☆過路亽.° 提交于 2019-11-30 12:11:33
一、DDL数据定义语言 建库、建表、设置约束等:create\drop\alter,DDL操作是隐性提交的!不能rollback 。 1、创建数据库: create database if not exists hncu characert set utf8; 2、创建表格: use hncu; create table if not exists study( id int, name varchar(30), age int ); 3、更改表结构(设置约束) desc study; //查看表结构 alter table stud drop column age; alter table stud add column age int; 4、删除表、删除数据库 drop table study; drop database hncu; 二、DML 数据操纵语言 主要指数据的增删查改: delete\update\insert 数据操纵语言DML主要有三种形式: 插入:INSERT 更新:UPDATE 删除:DELETE 三、DQL数据查询语言 数据查询语言DQL基本结构是由SELECT子句,FROM子句,WHERE 子句组成的查询块: SELECT <字段名表> FROM <表或视图名> WHERE <查询条件> 四、DCL数据控制语言

Renaming multiple columns in one statement with PostgreSQL

女生的网名这么多〃 提交于 2019-11-30 10:54:37
Is it possible to rename multiple columns in a single statement, something along the lines of: ALTER TABLE Users RENAME COLUMN userName TO user_name, RENAME COLUMN realName TO real_name; No. While other actions can be combined, that's not possible with RENAME . The manual: All the forms of ALTER TABLE that act on a single table, except RENAME , SET SCHEMA , ATTACH PARTITION , and DETACH PARTITION can be combined into a list of multiple alterations to be applied together. Since RENAME is a tiny operation on a system catalog, there is no harm in running multiple statements. Do it in a single