Skip to content
Advertisement

Adding a set to a database table, using format string – how to include null values

I have a set that depending on the situation can contain anywhere between 1 and 5 elements. I am saving this set to a database table using a format string. My table contains 5 tables, but when creating it, I did include that it was okay to have null values in the columns.

my set below can be:

but it can also be:

This is my insert statement within my database table.

I know that I need to find a way to make my table accept the set, even without 5 values in the set and include null values in the empty spaces.

Any help, advice would be great!

Advertisement

Answer

You need convert your set into a list and then add None to the list for each missing value. You could append None for each missing value or create a list of None and extend your “small” list.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement