Need to rename partition and set the new location for an external table all in one statement.
alter table A partition(part='A') rename to partition (part='B');
alter table A partition(part='B') set location 's3://...';
I am trying to see if this can be combined in to single statement
alter table A partition(part='A') rename to partition(part='B') set location 's3://'..'
Related
I have couple of indexed views (with schema binding and index) in my database.
I want to alter some some columns used by the view, but I get:
The object 'MyIndexedView' is dependent on the column 'MyColumn'.
ALTER TABLE ALTER COLUMN MyColumn because one or more objects access this column.
Is there a script that would allow me to:
drop the view
execute my ALTER TABLE scripts
recreate the view and indexes
Something like
-- 0. catch the schema and indexes
declare #definitionBackup VARCHAR(MAX) = getDefinitionWithIndexes('dbo', 'MyIndexedView');
-- 1. drop
DROP VIEW dbo.MyIndexedView
-- 2. update
ALTER TABLE .....
-- 4. recreate
EXEC (#definitionBackup)
I'm planning to truncate the hive external table which has one partition. So, I have used the following command to truncate the table :
hive> truncate table abc;
But, it is throwing me an error stating : Cannot truncate non-managed table abc.
Can anyone please suggest me out regarding the same ...
Make your table MANAGED first:
ALTER TABLE abc SET TBLPROPERTIES('EXTERNAL'='FALSE');
Then truncate:
truncate table abc;
And finally you can make it external again:
ALTER TABLE abc SET TBLPROPERTIES('EXTERNAL'='TRUE');
By default, TRUNCATE TABLE is supported only on managed tables. Attempting to truncate an external table results in the following error:
Error: org.apache.spark.sql.AnalysisException: Operation not allowed: TRUNCATE TABLE on external tables
Action Required
Change applications. Do not attempt to run TRUNCATE TABLE on an external table.
Alternatively, change applications to alter a table property to set external.table.purge to true to allow truncation of an external table:
ALTER TABLE mytable SET TBLPROPERTIES ('external.table.purge'='true');
There is an even better solution to this, which is basically a one liner.
insert overwrite table table_xyz select * from table_xyz where 1=2;
This code will delete all the files and create a blank file in the external folder location with absolute zero records.
Look at https://issues.apache.org/jira/browse/HIVE-4367 : use
truncate table my_ext_table force;
I need to alter my table and change a VARCHAR2 column to be CLOB.
The following script is too slow (8 minutes) for me when having 1 million records:
ALTER TABLE SA.EVENT_PARAMS ADD COLUMN NEW_VALUE CLOB(65344);
UPDATE SA.EVENT_PARAMS SET NEW_VALUE=VALUE;
ALTER TABLE SA.EVENT_PARAMS DROP COLUMN VALUE;
RENAME COLUMN SA.EVENT_PARAMS.NEW_VALUE TO VALUE;
Is there another way to do this? Talking about apache derby.
Thanks
I am attempting to create a table in Hive environment and point it to an external location in S3.
When I try :
create table x (key int, value string) location 's3/...'
it works well.
But, when I attempt :
'create external table as select x,y,z from alphabet location 's3/...'
it doesn't run. Is there a way to create a table as a select statement and store it at an external location?
You can create a managed table using the select statement and update the table property to External.
ALTER TABLE <table name> SET TBLPROPERTIES('EXTERNAL'='TRUE')
or
Write the output of the select query to a location
INSERT OVERWRITE DIRECTORY ‘/myDirectory’
SELECT * FROM PARAGRAPH;
CREATE EXTERNAL TABLE <table name> LOCATION '/myDirectory'
I have a Firebird database with several tables in it. There are several columns who were added when database was created as
alter table Machines add MachineVersion varchar(100) CHARACTER SET UNICODE_FSS
I want to modify these columns to drop the CHARACTER SET UNICODE_FSS so I ran the command
alter table Machines alter column MachineVersion type VARCHAR(100)
Still, when I open the database in SQL Manager the character set for these columns is still UNICODE_FSS.
Is there another syntax for the second command to remove the CHARACTER SET UNICODE_FSS?
alter table Machines alter column MachineVersion type VARCHAR(100)
This query won't change the character set.
If you want to remove charater set you should alter domain like:
update RDB$FIELDS set
RDB$CHARACTER_SET_ID = NULL
where RDB$FIELD_NAME = 'RDB$141'
Instead of RDB$141 use column domain
It is possible to add new column , copy data from old column to new and later to drop old column?