create-table

csv file to hive table using load data - How to format the date in csv to accept by hive table

删除回忆录丶 提交于 2019-12-06 12:20:48
问题 I am using load data syntax to load a csv file to a table.The file is same format as hive accepts. But still after load data is issued, Last 2 columns returns null on select. 1750,651,'2013-03-11','2013-03-17' 1751,652,'2013-03-18','2013-03-24' 1752,653,'2013-03-25','2013-03-31' 1753,654,'2013-04-01','2013-04-07' create table dattable( DATANUM INT, ENTRYNUM BIGINT, START_DATE DATE, END_DATE DATE ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ; LOAD DATA LOCAL INPATH '/path/dtatable.csv'

Can I dynamically create a mySQL table from JSON?

蓝咒 提交于 2019-12-06 11:27:52
问题 Let's say I have a server side script which generates JSON from a simple select on a table. The JSON is encoded in the 1st script. I have no control over this 1st script, but am aware when the underlying database structure changes and when the JSON structure changes. Script 2 uses CURL to get the .js file (contents) which contains the JSON, I can then decode into an array. What I need to do then is store the data in another database. My question is basically about automating this process and

CREATE TABLE new_table_name LIKE old_table_name with old_table_name's AUTO_INCREMENT values

最后都变了- 提交于 2019-12-06 06:57:50
Can I create a new table with an old table's autoincriment status in mysql client? I think, that ALTER TABLE new_table_name AUTO_INCREMENT=@my_autoincr_iment helps me, but this construction must use with a constant value. I don't want to use a difficult script. mysql> create table new_table like old_table; mysql> select @my_auto_increment:=auto_increment from information_schema.tables where table_name='old_table'; mysql> set @query = CONCAT("alter table new_table auto_increment = ", @my_auto_increment); mysql> prepare stmt from @query; mysql> execute stmt; mysql> deallocate prepare stmt; Thx

Mysql errno 150 trying to create table with foreign key references

不羁岁月 提交于 2019-12-05 23:41:17
I'm trying to create a table in mysql with a foreign key reference, like this: In database A: CREATE TABLE replication ( id varchar(255) NOT NULL PRIMARY KEY, uid varchar(255) NOT NULL, value int(11) NOT NULL, FOREIGN KEY (uid) REFERENCES databaseB.users(username) ); In database B i have a table named users like this: +-----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+-------+ | id | varchar(255) | NO | | NULL | | | username | varchar(255) | NO | PRI | NULL | | +-------------

HIVE - INSERT OVERWRITE vs DROP TABLE + CREATE TABLE + INSERT INTO

落爺英雄遲暮 提交于 2019-12-05 17:11:31
问题 I'm doing some automatic script of few queries in hive and we found that we need time to time clear the data from a table and insert the new one. And we are thinking what could be faster? INSERT OVERWRITE TABLE SOME_TABLE SELECT * FROM OTHER_TABLE; or is faster to do like this: DROP TABLE SOME_TABLE; CREATE TABLE SOME_TABLE (STUFFS); INSERT INTO TABLE SELECT * FROM OTHER_TABLE; The overhead of running the queries is not an issue. Due to we have the script o creation too. The question is, the

Storing the results of a prepared statement as a table in mysql?

若如初见. 提交于 2019-12-05 14:23:46
Is it possible to store the result of a prepared table in mysql ? My use case is - : I am creating two variables based on certain conditions of the source table, then fetching the randomized rows, based on this criteria. Since I have 10 of such tables, should I be 1st joining them and then doing this randomization on the "overall" passing/filtering criteria (See also @total below, which is my main criteria, PER table) set @total=(select count(*) from tab_1 where predict_var ="4" or predict_var ="2" ) ; set @sample= ( select @total*(70/30)) ; PREPARE STMT FROM " SELECT * FROM tab_1 WHERE

Create new Table in ruby on rails

孤人 提交于 2019-12-05 11:10:35
问题 I try to create a new table in rails. Every example I find and try sadly does not work with me... so that's what I tried till now: (I use Ruby version 1.9 and Rails Version 3.2.13 making a new model in the terminal: rails generate model content content_id:auto-generated, law_id:integer, parent_id:integer, titel:string, text:string, content:string, url:string that generated following code: class CreateContents < ActiveRecord::Migration def change create_table :contents do |t| t.auto-generated,

PostgreSQL - Create table and set specific date format

随声附和 提交于 2019-12-05 10:51:21
I want to create a new table and set a date type with a specific format. Is that possible? For example: CREATE TABLE User ( ... EXPIRATION DATE " YYYY/MM" ... ) Erwin Brandstetter I suggest a different approach: Never store date / time as character type ( text , varchar() , ...) to begin with. Use an appropriate type , probably date in your case. Also, never use reserved words as identifier. user is just not possible to begin with, you would have to double-quote, which I would discourage. Could look like this: CREATE TABLE usr ( usr_id serial PRIMARY KEY ,usr text UNIQUE ,expiration_date date

CREATE TABLE permission denied in database 'tempdb'

不打扰是莪最后的温柔 提交于 2019-12-05 10:46:25
问题 First time I installed SQL Server Management Studio Express and Visual Studio 2005 on my system. Now I am trying to create table by using below script. But if once I execute I am facing error like CREATE TABLE permission denied in database 'tempdb'. Why it it? Can anyone help me how to resolve this ? USE [tempdb] GO SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Employee] ([FirstName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [LastName] [nvarchar](50)

How to create table if not exists with HSQLDB

梦想与她 提交于 2019-12-05 00:54:26
I'm using HSQLDB for persisting a small data, in my query I want to create tables at first time and if they are not exist anymore. However with HSQLDB I cannot execute the query "CREATE TABLE XYS IF NOT EXISTS" like other dbms like mysql or mssql. Please give me solution for this case. HSQLDB supports the syntax like the example below: CREATE TABLE IF NOT EXISTS xyx (a int, b varchar(10)) The syntax is supported by recent HSQLDB 2.3.X versions. 来源: https://stackoverflow.com/questions/21814489/how-to-create-table-if-not-exists-with-hsqldb