GPP
GPP

Reputation: 2325

Setup Big Query table with UUID column?

Between the "BigQuery default column value" and "Create UUID columns in BigQuery" posts, it looks like BQ recently started supporting the concept of a UUID, but is there a pattern for generating UUID (similar to a postgres/SQL trigger) values for each record upon insertion into the BQ table?

As an aside, I'm not seeing a way to automatically generate timestamp values for created_date_time and modified_date_time (typically another trigger) fields-- should I just focus on generating these values (UUIDs and timestamps) in the logic making the insertion request?

Upvotes: 0

Views: 1743

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270463

BigQuery supports neither default values nor triggers. So, you have to assign these values explicitly when rows are inserted:

create table `test` (
    id string,
    x int64,
    created_at timestamp
);

INSERT INTO `test` (id, x, created_at)
    values (generate_uuid(), 1, current_timestamp);

I imagine that Google will add default values in the not-to-distant future.

Upvotes: 2

Related Questions