# Inserting string "NULL" into column

**URL:** <https://forum.liquibase.org/t/inserting-string-null-into-column/742>\
**Category:** General Discussion\
**Created:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742 "2010-08-19T09:30:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dean.m.jones](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@dean.m.jones](https://forum.liquibase.org/u/dean.m.jones)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/1 "2010-08-19T09:30:00Z")

</div>

Hello folks,

I’m currently trying to get our existing liquibase changesets working with the head of the liquibase trunk. We have some existing changesets that insert the string “NULL” as a value (i.e. not setting the column to , but inserting the string “NULL”). We also have other changesets that insert an empty string as a value. Prior to revision 1678 ([http://liquibase.jira.com/source/changelog/CORE/?name=otaranenko&cs=1678),](http://liquibase.jira.com/source/changelog/CORE/?name=otaranenko&cs=1678),) trying to insert an empty string would result in a value, which is not what we wanted; post-1678, we can insert an empty string, but now inserting the string “NULL” results in a value, which is also not what we want. How do I now insert the string “NULL” as a value?

Thanks,

Dean.

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/2 "2010-08-19T09:30:00Z")

</div>

I’ll look at the issue and try to fix it

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/3 "2010-08-19T09:30:00Z")

</div>

In the integration tests all such examples correctly inserts null values.

Dean, could you please supply your change set.  
Is it not in the loadData tag?

---

<div class="post-metadata">

**Author:** ![dean.m.jones](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@dean.m.jones](https://forum.liquibase.org/u/dean.m.jones)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/4 "2010-08-19T09:30:00Z")

</div>

Hi, thanks for quick response. I have a changeset which looks something like:

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

In this case, I’d like the column ‘myString’ to contain the string “null”, but instead I get a null value for that column.

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/5 "2010-08-19T09:30:00Z")

</div>

> _Originally posted by: dean_  
> Hi, thanks for quick response. I have a changeset which looks something like: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
> 
> In this case, I’d like the column ‘myString’ to contain the string “null”, but instead I get a null value for that column.

Ah-h-h… I gotcha, what you mean. I thought quite the contrary. “NULL” in such situation must be treated as value. To support your case I suggest add additional attribute at the changeSet level, say nullAsStringValue=“true”. If no has objection I could add this.  
Or may be someone has another idea?

Cheers, Oleg

---

<div class="post-metadata">

**Author:** ![dean.m.jones](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@dean.m.jones](https://forum.liquibase.org/u/dean.m.jones)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/6 "2010-08-19T09:30:00Z")

</div>

What was the behaviour with value=“null” at v1.x? Probably best to keep this previous behaviour, whatever it was. The “nullAsStringValue” attribute would be fine with me.

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/7 "2010-08-19T09:30:00Z")

</div>

> _Originally posted by: dean_  
> What was the behaviour with value="null" at v1.x? Probably best to keep this previous behaviour, whatever it was. The "nullAsStringValue" attribute would be fine with me.

I'm not sure, if that behavior was specially stated but not occasionally. If so, we have a chance to correct how it is right. I think about another format of xml. May be 
&nbsp; &nbsp; &nbsp; &nbsp; 
sounds better? In this case we can handle in one insert statement and "null" values.

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/8 "2010-08-19T09:30:00Z")

</div>

I saw change 1678 come through that changed the 1.9 behavior of empty=null, which is probably good.&nbsp; With 1.9 we didn’t have a great answer to empty string vs. null vs “null”, and whatever change we make will break existing changesets.&nbsp;

I’m thinking the best option is to have a more special value like \null\ that we use to actually mean null.&nbsp; So you can say value="" and get an empty string, value=“null” and get the string “null” and value="\null" to be a null value.&nbsp; That way we don’t need an addtional attribute, which will also help with other formats like .csv data imports that can use \null\ as a value.

For 1.9-\>2.0 conversion, it may be worth adding a changeLog file-wide attribute of “emptyStringMeansNull” that people with a 1.9 changelog can use to keep the old behavior.&nbsp; You would need to add a switch to what was changed in 1678.&nbsp; You should be able to get a handle on the databaseChangeLog object to check the state of the flag.

Nathan

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/9 "2010-08-19T09:30:00Z")

</div>

at start value="\null" looks good, but what will you do, if someone wanna insert “\null” as string? Enforce he to write “\null\”? And this will occurs with any string, you can imagine. No warranty about an exception.  
At my taste, method with attribute is the only way to untie that knot.  
As for import in .csv i suggest the same manner: bare null is and “null” is a string value. Double quotes is already reserves character in the parser. We could make a decision using such manner.

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/10 "2010-08-19T09:30:00Z")

</div>

I like better than \null\ for a special value.&nbsp; It’s more SQL-like, less code-like.&nbsp;

I think to handle inserting “” as a string, we would just need to allow escaping like watching for “\<null\>”&nbsp; It’s enough of an edge case (is that a string anyone would ever really want to insert into a database?), I think we can handle the escaping at a later time, though.

Nathan

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/11 "2010-08-19T09:30:00Z")

</div>

I’m convincing the syntax for any action should be as simple as possible.  
It will facilitate using any program tool in the future and for any. Syntactic-sugar?

Therefore an attribute base approach to avoid remember the exact escaping for null values.  
It will avoid hard-coded null value escaping in the codebase too.

&nbsp; &nbsp; &nbsp; case #1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp; case #2  
&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

both #1 and #2 produce  
insert into TestTable(myNull, myString) values(null,‘null’);

#1 attribute escapeNull (default=“true”) allows fine-grained handling of the values. For example null, ‘null’ and ‘\null’ values in the same insert/update clause  
#2 attribute nullSubstitue (default=“null”) allows avoid verbose for regular data

&nbsp; &nbsp; #3 &nbsp; &nbsp; #4

testNull.csv::  
myNull,myString  
null,\null

#3 =\> insert into TestTable(myNull, myString) values(null,’\null’);  
#4 =\> insert into TestTable(myNull, myString) values(‘null’,null);

Note for csv import there is no possible row-level handling of the edge. It should be split into different csv files.

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/12 "2010-08-19T09:30:00Z")

</div>

I agree it should be simple, that’s why I’m thinking it should just be a single value that we handle as null in whatever form the changeset is in: xml, csv, or anything else without needing to worry about escapeNull or nullSubstitue parameters.&nbsp; If we have null values in different formats, I think that would make it more difficult for future tools to handle.

would have problems with the angle brackets because of XML, however.&nbsp; Maybe {null} is better?

(note: I’ll be on vacation from the 21st to the 29th and may not be able to respond for a while)

Nathan

---

<div class="post-metadata">

**Author:** ![dean.m.jones](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@dean.m.jones](https://forum.liquibase.org/u/dean.m.jones)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/13 "2010-08-19T09:30:00Z")

</div>

Hello Nathan, Oleg,

Did you reach a resolution on this issue? We’re still suffering from this problem with the version of liquibase we’re running with (revision 1719 of trunk). Thanks,

Dean.

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/14 "2010-08-19T09:30:00Z")

</div>

no, we did not \>:(  
for me personally changing null to {null} follows to problem with currently supported liquibase projects. That’s why I’ve suggested the approach with nullSubstitute solution. nullSubstitude will allow avoid a lot of additional work to keep current checksums. In my case the current csv files will not be changed, only adding an attribute in changeset tag.

May be add nullSubstitude attribute at the \<databaseChangeLog …\> level? By default \<databaseChangeLog nullSubstitude="{null}" or what ever you want…

Nathan?

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/15 "2010-08-19T09:30:00Z")

</div>

That is a good point about needing to support the existing 1.9 style to not break checksums.&nbsp; With 2.0 we are already breaking checksums, but there are many people that have already been running 2.0 and it would be good to not cause them more problems than we need to.&nbsp;

Given that, I think it would be best to introduce a new attribute to control which value means NULL.&nbsp; For backwards compatibility and for least surprising, I think we should keep the default value as “NULL”.&nbsp; However, you can set the nullSubstitute attribute at the changeSet or the changeLog level and override the value that liquibase looks for.&nbsp; I think “nullPlaceholder” would be a better attribute value, though.&nbsp; Any other suggestions?

So the normal behavior would be to have and it would have a value of NULL.&nbsp; You can set nullPlaceholder to anything you want ("{null} ", “REALLY\_A\_NULL”, etc) on the changeSet tag or the databaseChangeLog tag to allow you to set the value as the string null.

Nathan

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/16 "2010-08-19T09:30:00Z")

</div>

Thank you Nathan, nullPlaceholder sounds better.

Would it be case sensitive? I hope yes. In that case syntax will be more intuitive. I.e.

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
allows to insert null as a string, what dean wants
insert into TestTable(myNull, myString) values(null,'null');

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/17 "2010-08-19T09:30:00Z")

</div>

I’ll have to see what the convention was in 1.9 so that continues to work.&nbsp; I think case insensitive would actually be better, I find people have a hard time remembering what case to use, and I’m not sure why using NULL as a placeholder would be more or less intuitive than null as a placeholder.&nbsp;

You’d have to use something completely different than null if you want to insert “null” as a string:

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

Nathan

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/18 "2010-08-19T09:30:00Z")

</div>

case (in)sensitive is no problem to me 8-). Let see in 1.9 for compatible

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/19 "2010-08-19T09:30:00Z")

</div>

I undid the change the modified the 1.9 behavior.&nbsp; I also created an issue for nullPlaceholder ([http://liquibase.jira.com/browse/CORE-722)](http://liquibase.jira.com/browse/CORE-722)) but will not tackle it until post-2.0

Nathan

---

<div class="post-metadata">

**Author:** ![taranenko](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@taranenko](https://forum.liquibase.org/u/taranenko)\
**Post date:** [August 19, 2010, 9:30am UTC](https://forum.liquibase.org/t/inserting-string-null-into-column/742/20 "2010-08-19T09:30:00Z")

</div>

How to insert the empty string now? emptyPlaceholder=“empty”?

This is a bug in 1.9 and as I said before, we need to fix it.  
If you take care about 1.9 =\> 2.0 compability, checksums are breaking anyway. Along with checksum correction, it is possible to write the xslt script to convert the 1.9-style changelog files to new standard with “” as empty string, “null” for null value (as a default for nullPlaceholder).  
And also I think it is better introduce the nullPlaceholder right now, BEFORE 2.0 release to avoid additional changes of the changeset’s files later.

[Next page](https://forum.liquibase.org/t/inserting-string-null-into-column/742.md?page=2)
