Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create table SQL syntax in Google Bigquery

I've been reading the bigquery documentation since late last night and understand very little of it. It talks about loading data via different methods, but doesn't say how to create the table that I'm going to load data into. When I use the web UI it expects me to type out the schema. My table has over 400 columns. I will not type out hundreds of column names, types and lengths.

I've been uploading hundreds of GB of data in csv format to a google bucket. The csv files do not have column names. I have the schema in sql format which I prefer to use.

If I try creating a table through a query I get an error already on line 2 that says,

"Error: Encountered "" at line 2, column 1."

CREATE TABLE [example-mdi:myData_1.ST] (
`ADDRESS_ID` varchar(9),
`INDIVIDUAL_ID` varchar(2),
`FIRST_NAME` varchar(25),
`LAST_NAME` varchar(2),...

How can I do this or what is the right way?

like image 344
Altimus Prime Avatar asked Dec 09 '16 12:12

Altimus Prime


Video Answer


2 Answers

You can use a CREATE TABLE statement to create the table using standard SQL. In your case the statement would look something like this:

CREATE TABLE `example-mdi.myData_1.ST` (
  `ADDRESS_ID` STRING,
  `INDIVIDUAL_ID` STRING,
  `FIRST_NAME` STRING,
  `LAST_NAME` STRING,
  ...
);
like image 61
Elliott Brossard Avatar answered Oct 19 '22 23:10

Elliott Brossard


Mikhail is right and gets credit for the answer. If you're as slow as me you're going to want more details, because after he pointed me the right way it still took a while to figure out what he's talking about and how to get it done.

When you're at the create table user interface click the "edit as text" link.

enter image description here

In the text box input that pops up you'll enter something like:

ADDRESS_ID:string,
INDIVIDUAL_ID:string,
First_name:string,
Last_name:string...

Hyphens are not permitted.

like image 24
Altimus Prime Avatar answered Oct 19 '22 22:10

Altimus Prime