Below is the syntax to create a new table in Redshift database: CREATE TABLE tablename ( column1 datatype, column2 datatype,
Continue readingCategory: Redshift
How to add column to a table in Redshift
Below is the syntax to add a new column to an existing table in Redshift database. ALTER TABLE table_name ADD
Continue readingHow to create a group and add users to group in Redshift
create group group_name; GRANT USAGE ON SCHEMA schema_name TO GROUP group_name; alter group group_name add user user_name; commit;
Continue readingHow to change column data type in Redshift
BEGIN TRANSACTION; ALTER TABLE schemaname.tablename RENAME TO tablename_old; CREATE TABLE schemaname.tablename (); –New definition INSERT INTO schemaname.tablename SELECT * FROM
Continue readingHow to change the table owner of a Redshift table
Check the current owner of the table using the below query where table_name is the name of your table and
Continue readingHow to add Sort and Dist Keys to an existing Redshift table
Command to Add or Modify a Sort key: ALTER TABLE schema.table_name ALTER SORTKEY (column_name); Command to Add or Modify a
Continue readingHow to kill sessions in Redshift
Identify the session that you would like to terminate from the below view and copy the process id. SELECT *
Continue readingAlter table commands for Redshift
ALTER TABLE table_name OWNER TO new_owner; ALTER TABLE table_name RENAME TO new_name; ALTER TABLE table_name ADD column_name column_type; ALTER TABLE
Continue readingHow to unload and copy data in Redshift
unload (‘SELECT * from schemaname.tablename’)TO ‘s3://bucketname/filename’credentials ‘aws_access_key_id=XXXXXX;aws_secret_access_key=XXXXX’DELIMITER ‘|’allowoverwriteESCAPE; copy schemaname.tablenamefrom ‘s3://bucketname/filename’credentials ‘aws_access_key_id=XXXXXX;aws_secret_access_key=XXXXX’DELIMITER ‘|’ESCAPE;
Continue readingHow to Create user in Redshift database
CREATE USER username PASSWORD ‘password‘; CREATE USER username PASSWORD ‘password‘ CREATEDB; CREATE USER username PASSWORD ‘password‘ CREATEDB CREATEUSER; CREATE USER
Continue reading