Opened 12 years ago

Closed 12 years ago

#1876 closed bug (fixed)

PostgreSQL text fields become zero-length strings when blanked on attribute update edits from QGIS

Reported by: mwtoews Owned by: jef
Priority: major: does not work as expected Milestone: Version 1.2.0
Component: Data Provider Version: Trunk
Keywords: Cc:
Must Fix for Release: No Platform: All
Platform Version: Awaiting user input: no

Description

This bug is simple to create in QGIS 1.0.x and 1.2.x.

Edit any PostGIS layer with several text fields:

  1. Add a geometry feature in QGIS, but leave some text fields blank when adding attributes; commit
  2. View database record in another client app (e.g., PgAdminIII) to ensure that blank fields are NULL
  3. Edit the feature attributes by adding text to a NULL field;
  4. In QGIS, edit the feature attributes, but delete the text; commit

The text field will now have a zero length text value '' and not a NULL value. I have observed zero-length strings "contaminating" my database, and I can source these oddities to QGIS edits from when someone blanks out text from fields that previously had non-zero length text.

Strictly speaking, this is not a bug, but is in a grey-area leaning toward "feature". Many client apps, like MS Access and pgAdminIII, consider zero-length strings to be NULLs. I prefer this behaviour, since it is consistent to the creation of the features in QGIS when no text has been added to some fields these were inserted as NULLs and not zero-length strings.

As a suggested solution, borrow the behaviour from pgAdminIII, whereby an empty field is always interpreted as NULL, and a zero-length text string has the literal '' (two consecutive single apostrophes). The zero-length literal should still be available for columns that are text but cannot be NULL.

Change History (2)

comment:1 in reply to:  description Changed 12 years ago by jef

Owner: changed from nobody to jef

Replying to mwtoews:

Strictly speaking, this is not a bug, but is in a grey-area leaning toward "feature".

Well, I consider it a bug. 1. NULL and an empty string are different values. And 2. if you don't touch the value, the value should stay the same.

I already fixed that once back in r8217. In r11392 I fixed it again. When editing empty strings are considered NULL in case of numeric values. For strings the literate string NULL is considered NULL.

comment:2 Changed 12 years ago by jef

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.