I'm trying to migrate data from a MySQL table to a BigQuery table using Python, but it gives me the following error when I try to insert a NULL value:
google.cloud.bigquery.dbapi.exceptions.ProgrammingError: Encountered parameter None with value None of unexpected type.
from dotenv import load_dotenv
load_dotenv() ##GOOGLE_APPLICATION_CREDENTIALS = 'api/google.json'
from google.cloud import bigquery
from google.cloud.bigquery import dbapi
import datetime
client = bigquery.Client()
connection = dbapi.Connection(client)
def write(query, data):
cursor = connection.cursor()
cursor.execute(query, data)
connection.commit()
return 'OK!'
data = (9, '857', '11013', None, datetime.datetime(2022, 9, 28, 15, 33, 13), datetime.datetime(2022, 9, 28, 15, 33, 13))
query = """
INSERT INTO `<project>.<dataset>.tmp_accountContacts`
(
id,account,contact,jobTitle,createdTimestamp,updatedTimestamp)
VALUES (%s,%s,%s,%s,%s,%s);
"""
write(query, data)
What's the issue?
jobTitleisstringcan you please try:VALUES (%s,%s,%s,%(:string)s,%s,%s);and let me know if that works?