Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select All Columns Except Some in Google BigQuery?

Is there a way to Select * except [x,y,z column names] in BigQuery? I see some solutions for MySQL but not sure if it applies to BQ.

Thank you.

like image 776
wubr2000 Avatar asked Dec 03 '15 01:12

wubr2000


People also ask

How do I SELECT all columns except one in BigQuery?

A SELECT * EXCEPT statement specifies the names of one or more columns to exclude from the result. All matching column names are omitted from the output. Note: SELECT * EXCEPT does not exclude columns that do not have names.

How do I SELECT a column in BigQuery?

To select the data from all the columns, rather than listing all the column names separated by a comma, add a star or asterisk syntax, and it is the same SELECT list of columns and add the table name. In BigQuery, SQL statement will allow us to look at the data in a particular table.

How do you use limits in BigQuery?

The following limits apply when you load data into BigQuery, using the console, the bq command-line tool, or the load-type jobs. insert API method. Load jobs, including failed load jobs, count toward the limit on the number of table operations per day for the destination table.


2 Answers

There is nothing in current BigQuery SQL dialect that will allow it. But since this is recurring request, we have added work item to support

SELECT * EXCEPT (a, b, c) FROM ... 

Update: This functionality is now available in BigQuery standard SQL. Details at https://cloud.google.com/bigquery/sql-reference/enabling-standard-sql Example using public wikipedia table - select all columns except title and comment:

select * except(title, comment) from publicdata.samples.wikipedia limit 10 
like image 100
Mosha Pasumansky Avatar answered Sep 20 '22 15:09

Mosha Pasumansky


In addition to SELECT * EXCEPT() syntax there is a SELECT * REPLACE() syntax - both supported with Standard SQL introduced
Usage is simple and obvious as per documentation

What is less obvious is that you can use both together in the same SELECT, like in example below

WITH orders AS   (SELECT 5 as order_id,   "sprocket" as item_name,   200 as quantity) SELECT * EXCEPT (order_id) REPLACE ("widget" AS item_name), "more" as more_fields FROM orders; 
like image 33
Mikhail Berlyant Avatar answered Sep 17 '22 15:09

Mikhail Berlyant