aman agrawal
aman agrawal

Reputation: 174

Unable to create table in hive

I am creating table in hive like:

CREATE TABLE SEQUENCE_TABLE(
  SEQUENCE_NAME VARCHAR2(225) NOT NULL,
  NEXT_VAL NUMBER NOT NULL
);

But, in result there is parse exception. Unable to read Varchar2(225) NOT NULL. Can anyone guide me that how to create table like given above and any other process to provide path for it.

Upvotes: 0

Views: 1943

Answers (3)

Krunal Makwana
Krunal Makwana

Reputation: 37

Use following syntax...

CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.] table_name

[(col_name data_type [COMMENT col_comment], ...)]
[COMMENT table_comment]
[ROW FORMAT row_format]
[STORED AS file_format]

And Example of hive create table

CREATE TABLE IF NOT EXISTS employee ( eid int, name String,
salary String, destination String)
COMMENT ‘Employee details’
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘\t’
LINES TERMINATED BY ‘\n’
STORED AS TEXTFILE;

Upvotes: 1

ChikuMiku
ChikuMiku

Reputation: 509

only you have option here like:

CREATE TABLE SEQUENCE_TABLE(SEQUENCE_NAME String,NEXT_VAL bigint) row format delimited fields terminated by ',' stored as textfile;

PS:Again depends the types to data you are going to load in hive

Upvotes: 0

Mariusz Sakowski
Mariusz Sakowski

Reputation: 3280

There's no such thing as VARCHAR, field width or NOT NULL clause in hive.

CREATE TABLE SEQUENCE_TABLE( SEQUENCE_TABLE string, NEXT_VAL bigint);

Please read this for CREATE TABLE syntax: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable

Anyway Hive is "SQL Like" but it's not "SQL". I wouldn't use it for things such as sequence table as you don't have support for transactions, locking, keys and everything you are familiar with from Oracle (though I think that in new version there is simple support for transactions, updates, deletes, etc.). I would consider using normal OLTP database for whatever you are trying to achieve

Upvotes: 1

Related Questions