Insert NULL in Google Cloud SQL using CSV import
Asked Answered
V

1

6

I am importing CSV files into Google Cloud SQL using its import functionality. It allows to import data into a Cloud SQL table.

API reference: https://cloud.google.com/sql/docs/admin-api/v1beta4/instances/import

If I use a CSV row with empty values, like:

,,,,42,,

I am getting 0 values in the SQL table. I would like to get NULL values instead. Is it possible ?

Vizzone answered 10/1, 2017 at 11:24 Comment(4)
Actually, my question applies to several languages and can be replicated using Google Cloud UI alone. So, is a code snippet going to be helpful ?Vizzone
Hi @JoseKilo, did you manage to solve this? Any 2018 updates?Taryntaryne
Not really. It's been a while. I think I ended up changing the way I generated my CSVs. Sorry. I would try something like this (I think this functionality is/was based on MySQL LOAD DATA) https://mcmap.net/q/47427/-mysql-load-null-values-from-csv-data But I think I already tried that back in the day.Vizzone
Update from 2022 and using postgres w/ CloudSQL. Empty columns are interpreted as null. E.g. "id",,"some val" would be copied as ["id", NULL, "some val"]Costume
C
0

I found it to work using NULL as a field value:

"gid://Customer/10031988754",0,0,"GBP","[]","GB"
"gid://Customer/1003793973310",0,NULL,NULL,"[]","GB"

this was unexpected, since CSV export generates entries with "N as NULL

Confessor answered 5/2, 2022 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.