I am trying to move a table which resides in a certain schema to a different schema with the same table name. I have tried the following but they do not work:
rename <OLD_SCHEMA_NAME>.<TABLE_NAME> TO <NEW_SCHEMA_NAME>.<TABLE_NAME>;
The error that appears is:
SQL Error [42000]: invalid identifier chain for new name [line 1, column 100] (Session: 1722923178259251200)
and
ALTER TABLE <OLD_SCHEMA_NAME>.<TABLE_NAME> RENAME <NEW_SCHEMA_NAME>.<TABLE_NAME>;
The error that appears is:
SQL Error [42000]: syntax error, unexpected IDENTIFIER_PART_, expecting COLUMN_ or CONSTRAINT_ [line 1, column 62] (Session: 1722923178259251200)
Many Thanks!
According to Exasol documentation there is no way to move table between schemas using RENAME statement:
Schema objects cannot be shifted to another schema with the RENAME
statement. For example, 'RENAME TABLE s1.t1 TO s2.t2' is not allowed.
I would move the table this way:
create table <NEW_SCHEMA_NAME>.<TABLE_NAME>
like <OLD_SCHEMA_NAME>.<TABLE_NAME>
including defaults
including identity
including comments;
insert into <NEW_SCHEMA_NAME>.<TABLE_NAME>
select *
from <OLD_SCHEMA_NAME>.<TABLE_NAME>;
drop table <OLD_SCHEMA_NAME>.<TABLE_NAME>;
Related
I have tried changing the column data type in Redshift via SQL. Keep getting an error:
[Amazon][Amazon Redshift] (30) Error occurred while trying to execute a query: [SQLState 42601] ERROR: syntax error at or near "TABLE" LINE 17: ALTER TABLE bmd_disruption_fv ^
Unable to connect to the Amazon Redshift server 'eceim.master.datamart.eceim.sin.auto.prod.c0.sq.com.sg'. Check that the server is running and that you have access privileges to the requested database
The first sql query works. I have tried writing the Alter Table script before the Select lines but it did not work too.
`
*Extract selected columns and renaming them for easier reference
*/
select ID, Completion_Time AS Date_Reported, Name2 AS Name, Contact_Info_for_updates AS Contact_Info,
Your_operation_line AS Operation_Line, Aircraft_Registration_SMU_SMT_etc AS Aircraft_Reg,
Designation_trade_B1_B2_ACT_AST_AAT AS Trade, Choose_your_Issue AS Issue, Manpower, Material, Equipment_GES,
Information, Tools, State_details_here_SVO_number_too AS Issue_Details, Time_wasted_on_due_to_issue AS Time_Wasted,
State_additional_comments_suggestions AS Additional_Comments, Stakeholders, Status
from bmdm.bmd_disruption_fv
/*Change colum data type
*/
ALTER TABLE bmd_disruption_fv
{
ALTER COLUMN ID TYPE INT
}
`
Several things are causing issues here. First the curly brackets '{}' should not be in the alter table statement. Like this:
alter table event alter column eventname type varchar(300);
Second, and likely more importantly, you can only change the length of varchar columns. So changing a column type to INT is not possible. You will need to perform a multistep process to make this change to the table.
I want to copy a table to another database server in SQL developer.
I use this method to solve this problem.
INSERT INTO mahdi-jiradb..empier SELECT * FROM tamindb..users;
but i get an error:
Error starting at line : 8 in command -
INSERT INTO mahdi-jiradb..empier
SELECT * FROM tamindb..users
Error at Command Line : 8 Column : 18
Error report -
SQL Error: ORA-00926: missing VALUES keyword
00926. 00000 - "missing VALUES keyword"
*Cause:
*Action:
What should i do?
As you commented, it looks as if you use Oracle.
In that case, schema name can't contain a "minus" sign (mahdi-jiradb) so that's probably underline (mahdi_jiradb) instead.
SQL> create user mahdi-jiradb identified by test;
create user mahdi-jiradb identified by test
*
ERROR at line 1:
ORA-00922: missing or invalid option
Unless, of course, you enclosed username into double quotes (but now you have to use it always, everywhere):
SQL> create user "mahdi-jiradb" identified by test;
User created.
Presuming that that's not the case, schema name is wrong. Check it.
Also, use one dot to separate schema name from table name.
Something like this might work:
INSERT INTO mahdi_jiradb.empier SELECT * FROM tamindb.users;
presuming that both tables share the same description. That's why it is better to explicitly name all columns involved, e.g.
INSERT INTO mahdi_jiradb.empier (user_id, user_name)
SELECT uid, uname FROM tamindb.users;
I have multiple tables with very similar schema except one column, which can have different names.
I want to make some complicated calculations using Hive and would like to have one code for all tables with possible parametrisation. For some reasons, I can't parametrise queries using language like Python, Scala etc, so decided to go with pure Hive SQL.
I want to conditionally select appropriate column, but it seems, that Hive evaluates all parts of conditional expression/statement regardless of condition.
What did I wrong?
DROP TABLE IF EXISTS `so_sample`;
CREATE TABLE `so_sample` (
`app_version` string
);
SELECT
if (true, app_version, software_version) AS firmware
FROM so_sample
;
Output:
Error: Error while compiling statement: FAILED: SemanticException [Error 10004]: Line 2:25 Invalid table alias or column reference 'software_version': (possible column names are: app_version) (state=42000,code=10004)
Regards
Pawel
Try to use regex to select the column with different names, for more information see manual and don't forget
set hive.support.quoted.identifiers=none;
I have a table named YY_ZZ_VAT_TRX_DETAILS under the XX schema.
It has an existing SYNONYM to AA schema.
I am currently logged in as AA and I wanted to add a column to YY_ZZ_VAT_TRX_DETAILS and executed the below command just fine
alter table XX.YY_ZZ_VAT_TRX_DETAILS
add (USER_DEFINED_FISC_CLASS VARCHAR2(30));
Table XX.YY_ZZ_VAT_TRX_DETAILS altered.
I tried to select the Column from the Table using the simple query below
select USER_DEFINED_FISC_CLASS
from YY_ZZ_VAT_TRX_DETAILS;
But I surprisingly got this error:
ORA-00904: "USER_DEFINED_FISC_CLASS": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action: Error at Line: 1 Column: 9
I thought I just missed altering the table, so I re-ran the ALTER script again, but got this error instead:
Error starting at line : 4 in command - alter table
XX.YY_ZZ_VAT_TRX_DETAILS add (USER_DEFINED_FISC_CLASS VARCHAR2(30))
Error report - ORA-01430: column being added already exists in table
01430. 00000 - "column being added already exists in table"
*Cause:
*Action:
I checked the Object Definition and sure enough, I found the new column there:
But when I query all the columns from the Table, I still can't see it:
select *
from YY_ZZ_VAT_TRX_DETAILS;
However, when I query using the XX schema prefix, I'm able to see the column:
select *
from XX.YY_ZZ_VAT_TRX_DETAILS;
Why isn't the synonym picking up the newly-added column?
It seems this was caused by this "Edition-Based Redefinition" thing that Oracle recently introduced for 12c.
Upon further investigation, what happened was:
The Table XX.XX_ZZ_VAT_TRX_DETAILS has a Editionable view named XX_ZZ_VAT_TRX_DETAILS# that only selects a certain number of columns.
Now, the View XX_ZZ_VAT_TRX_DETAILS# has a SYNONYM named XX_ZZ_VAT_TRX_DETAILS under the schema AA, hence the confusion on the Table having a SYNONYM of the same name.
To resolve this, i modified the view XX_ZZ_VAT_TRX_DETAILS# and added the new column and successfully recompiled it.
Once this was done, the synonym now shows the newly-added column and I was able to compile the stored procedure successfully.
I believe you could be having a table or a view called YY_ZZ_VAT_TRX_DETAILS or a private synonym that points to another table?.
In oracle the preference while querying is
1)objects_in same schema
2)private synonym
3)public synonym
I'm renaming two columns in two tables, both of which are named LEVEL, which is a reserved word.
What is confusing me greatly is that I am running an identical command on both these tables, but only one of them is failing. Here are the commands:
--this works
ALTER TABLE notificationsubscriptions RENAME COLUMN "LEVEL" TO nlevel;
--this doesn't
ALTER TABLE notifications RENAME COLUMN "LEVEL" TO nlevel;
The second statement results in the following error:
Error starting at line : 9 in command -
ALTER TABLE notifications RENAME COLUMN "LEVEL" TO nlevel
Error report -
SQL Error: ORA-00900: invalid SQL statement
00900. 00000 - "invalid SQL statement"
*Cause:
*Action:
Both these columns are of the same datatype (number). I am baffled - Why would this command work for one of these tables but not the other?
The database is running Oracle 10.2.
Try to remove any links that exist on this column from indexes and/or foreign key constraints
Drop indexes
Rename column
Create indexes with the new name of column