pgfutter icon indicating copy to clipboard operation
pgfutter copied to clipboard

Import text values as null instead of blank

Open ebbauer opened this issue 6 years ago • 2 comments

When importing data to a Postgres database use the copy command default behavior which is null values instead of blank ones.

For an experienced DBA, it is expected that the default value of a blank text field to be null because if you insert data on a table and do not specify any value as a default for that field the database is going to insert it as a null value.

quoting Postgres doc: "If no default value is declared explicitly, the default value is the null value. This usually makes sense because a null value can be considered to represent unknown data." - https://www.postgresql.org/docs/current/ddl-default.html

ebbauer avatar Feb 27 '19 18:02 ebbauer

Given the following example:

foo,"",bar
foo,,bar

Would you consider the first record to have an empty string and the second to have null?

raginjason avatar Sep 07 '19 02:09 raginjason

yes!

furthermore, we could have a parameter in cases like the first one where we would like it to be null. Something like --nullIf = "value" :smile:

ebbauer avatar Sep 12 '19 14:09 ebbauer