Can't do a CTAS when I use dbname in CTAS - hive

A piculiarity I noticed.
When I try
create table dbname.table_name as select
I get Error creating temporary folder on: hdfs://nameservice1/apps/hive/warehouse. Error encountered near token 'TOK_TMP_FILE'
But If I first do
use dbname;
and then
create table table_name as select
It works. Why is that?

To create table in any database user need to have write permission on current database and database in which table is being created.
I.e. while running create table dbname.table_name as select statement , you need to have write permission on current database as well.
This is known issue reported in jira HIVE-11427.

Related

How to create a temporary table in Oracle SQL when you get the error: insufficient privileges tips

I am using Toad and Oracle SQL.
I am trying to create a table as
create global temporary table tmptbl
on commit preserve rows as select * from mySchem.MyTable;
But I get an error
ORA-01031: insufficient privileges tips
Probably because I don't have the rights to save into mySchem.
However how can I get around the problem so I save the table locally somehow and I am ok with it if the table disappears when I close Toad. I am looking for creating a temporary "work table" as we know from SAS.
This post was not a help:
How do you create a temporary table in an Oracle database?
You need to grant CREATE TABLE in addition to have SELECT privileges to read the source table. There is no need to be able to write to the tablespace used by the source table because the temporary table will be stored in the default temporary tablespace.
Oracle workaround:– grant rights to create a table.
create global temporary table tmptbl
on commit preserve rows as select * from mySchem.MyTable;

Error in APEX SQL

I am working on Oracle 11g. I have created a table STUDENTS using APEX in my port: 8080 . After that when I use SQLPLUS in cmd and write SELECT * FROM STUDENTS it shows TABLE OR VIEW DOES NOT EXIST. What am I doing wrong here?
Ok...When you created the table using APEX, what schema was it created in? When you connect via SQL*Plus, are you logging in as the same user who owns the table?
If not, you'll need to grant select on the table to the user that wants to access the table, and also either specify the owner when referencing the table in your select statement, or create a synonym, or use alter session set current_schema statement.

SQL Error: ORA-00942 table or view does not exist

I use SQL developer and i made a connection to my database with the system user, after I created a user and made a another connection with that user with all needed privileges.
But when I try to proceed following I get the SQL Error
ORA-00942 table or view does not exist.:
INSERT INTO customer (c_id,name,surname) VALUES ('1','Micheal','Jackson')
Because this post is the top one found on stackoverflow when searching for "ORA-00942: table or view does not exist insert", I want to mention another possible cause of this error (at least in Oracle 12c): a table uses a sequence to set a default value and the user executing the insert query does not have select privilege on the sequence. This was my problem and it took me an unnecessarily long time to figure it out.
To reproduce the problem, execute the following SQL as user1:
create sequence seq_customer_id;
create table customer (
c_id number(10) default seq_customer_id.nextval primary key,
name varchar(100) not null,
surname varchar(100) not null
);
grant select, insert, update, delete on customer to user2;
Then, execute this insert statement as user2:
insert into user1.customer (name,surname) values ('michael','jackson');
The result will be "ORA-00942: table or view does not exist" even though user2 does have insert and select privileges on user1.customer table and is correctly prefixing the table with the schema owner name. To avoid the problem, you must grant select privilege on the sequence:
grant select on seq_customer_id to user2;
Either the user doesn't have privileges needed to see the table, the table doesn't exist or you are running the query in the wrong schema
Does the table exist?
select owner,
object_name
from dba_objects
where object_name = any ('CUSTOMER','customer');
What privileges did you grant?
grant select, insert on customer to user;
Are you running the query against the owner from the first query?
Case sensitive Tables (table names created with double-quotes) can throw this same error as well. See this answer for more information.
Simply wrap the table in double quotes:
INSERT INTO "customer" (c_id,name,surname) VALUES ('1','Micheal','Jackson')
You cannot directly access the table with the name 'customer'. Either it should be 'user1.customer' or create a synonym 'customer' for user2 pointing to 'user1.customer'. hope this helps..
Here is an answer: http://www.dba-oracle.com/concepts/synonyms.htm
An Oracle synonym basically allows you to create a pointer to an object that exists somewhere else. You need Oracle synonyms because when you are logged into Oracle, it looks for all objects you are querying in your schema (account). If they are not there, it will give you an error telling you that they do not exist.
I am using Oracle Database and i had same problem. Eventually i found ORACLE DB is converting all the metadata (table/sp/view/trigger) in upper case.
And i was trying how i wrote table name (myTempTable) in sql whereas it expect how it store table name in databsae (MYTEMPTABLE). Also same applicable on column name.
It is quite common problem with developer whoever used sql and now jumped into ORACLE DB.
in my case when i used asp.net core app i had a mistake in my sql query. If your database contains many schemas, you have to write schema_name before table_name, like:
Select * from SCHEMA_NAME.TABLE_NAME...
i hope it will helpful.

SELECT data from another schema in oracle

I want to execute a query that selects data from a different schema than the one specified in the DB connection (same Oracle server, same database, different schema)
I have an python app talking to an Oracle server. It opens a connection to database (server/schema) A, and executes select queries to tables inside that database.
I've tried the following :
select ....
from pct.pi_int, pct.pi_ma, pct.pi_es
where ...
But I get:
ORA-00942: table or view does not exist
I've also tried surrounding the schema name with brackets:
from [PCT].pi_int, [PCT].pi_ma, [PCAT].pi_es
I get:
ORA-00903: invalid table name
The queries are executed using the cx_Oracle python module from inside a Django app.
Can this be done or should I make a new db connection?
Does the user that you are using to connect to the database (user A in this example) have SELECT access on the objects in the PCT schema? Assuming that A does not have this access, you would get the "table or view does not exist" error.
Most likely, you need your DBA to grant user A access to whatever tables in the PCT schema that you need. Something like
GRANT SELECT ON pct.pi_int
TO a;
Once that is done, you should be able to refer to the objects in the PCT schema using the syntax pct.pi_int as you demonstrated initially in your question. The bracket syntax approach will not work.
In addition to grants, you can try creating synonyms. It will avoid the need for specifying the table owner schema every time.
From the connecting schema:
CREATE SYNONYM pi_int FOR pct.pi_int;
Then you can query pi_int as:
SELECT * FROM pi_int;
Depending on the schema/account you are using to connect to the database, I would suspect you are missing a grant to the account you are using to connect to the database.
Connect as PCT account in the database, then grant the account you are using select access for the table.
grant select on pi_int to Account_used_to_connect

how to drop user defined database in sql server 2005?

I am trying to drop a user-defined database, like so:
create database demo;
drop database demo;
But I get the error
Cannot drop the database 'demo',
because it does not exist or you do
not have permission.
One way to sort this out might be to run
SELECT name FROM sys.databases
to see if the database does exist.
Some helpful tips from MSDN:
To use DROP DATABASE, the database
context of the connection cannot be
the same as the database to be
dropped. You could change your
context to, for example USE master
before running DROP
To execute DROP DATABASE, at a
minimum, a user must have CONTROL
permission on the database.
You might find some other useful information there that applies to your specific situation.
create database demo;
drop database demo;
In the above code, if the database is deleted and again tried to delete the database which does not exists will give you the error as you mentioned