New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: recommend insert_rows_json to avoid call to tables.get #258
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
012934c
docs: recommend insert_rows_json to avoid call to tables.get
tswast 529f480
Merge branch 'master' into pr253-insert-rows-json
tswast f356a87
update comments
tswast a3b86be
Merge remote-tracking branch 'upstream/master' into pr253-insert-rows…
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
def table_insert_rows_explicit_none_insert_ids(table_id): | ||
|
||
# [START bigquery_table_insert_rows_explicit_none_insert_ids] | ||
|
||
from google.cloud import bigquery | ||
|
||
# Construct a BigQuery client object. | ||
|
@@ -25,12 +24,16 @@ def table_insert_rows_explicit_none_insert_ids(table_id): | |
# TODO(developer): Set table_id to the ID of the model to fetch. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment update here as well |
||
# table_id = "your-project.your_dataset.your_table" | ||
|
||
table = client.get_table(table_id) # Make an API request. | ||
rows_to_insert = [(u"Phred Phlyntstone", 32), (u"Wylma Phlyntstone", 29)] | ||
rows_to_insert = [ | ||
{u"full_name": u"Phred Phlyntstone", u"age": 32}, | ||
{u"full_name": u"Wylma Phlyntstone", u"age": 29}, | ||
] | ||
|
||
errors = client.insert_rows( | ||
table, rows_to_insert, row_ids=[None] * len(rows_to_insert) | ||
errors = client.insert_rows_json( | ||
table_id, rows_to_insert, row_ids=[None] * len(rows_to_insert) | ||
) # Make an API request. | ||
if errors == []: | ||
print("New rows have been added.") | ||
else: | ||
print("Encountered errors while inserting rows: {}".format(errors)) | ||
# [END bigquery_table_insert_rows_explicit_none_insert_ids] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment needs updated, there's no fetching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Good catch