-
Notifications
You must be signed in to change notification settings - Fork 322
Description
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Is your feature request related to a problem? Please describe.
I'm developing a wrapper library to use pydantic.BaseModel as means to define the TableSchema. As part of this wrapper, I would like to provide "server default" values, such as CURRENT_DATETIME, CURRENT_TIMESTAMP, so on, to datetime.datetime fields;
Describe the solution you'd like
client = bigquery.Client("someproject")
bq_table_schema_field = SchemaField(..., default_value_expression="CURRENT_DATETIME()")
table_with_default_value = Table("my_table", schema=[schema_field])
client.create_table(table_with_default_value)The field "defaultValueExpression" is a valid REST API field and would be a direct mapping from the initializer argument default_value_expression to the API "defaultValueExpression" field.
Describe alternatives you've considered
The alternative to this, would be construct a DDL statement for creating tables which columns can have default values via DEFAULT keyword
base_create = f"CREATE TABLE {somedataset_name}.{table_with_default_value.name} ("
for field in fields:
field_as_column_statement = f'{field.name} {as_bq_type(field.type)} {"DEFAULT" if field.has_server_default else ""} {field.server_default_statement if field.has_server_default else ""}, '
base_create = base_create + field_as_column_statement
base_create = base_create + ");"Which is very cumbersome and ugly, and useless, since the REST API already provides a field for default value expressions.