postgres returns "" for empty column values
postgres returns "" for empty column values
@@ -936,9 +936,25 @@ Document doc;
* SELECT oid, typname FROM pg_type;
*/
- Oid oid = PQftype(res, j);
- switch (oid) {
+ /**
+ * If PQgetvalue() is pointer to an empty string,
+ * we assume that is a NULL and we return
+ * the "" value no matter the OID value
+ */
+ if (!strlen(PQgetvalue(res, i, j)))
+ {
+ Value value("", allocator);
+ Value name(PQfname(res, j), allocator);
+ row.AddMember(name, value, allocator);
+ // Get the next column
+ continue;
+ }
+
+ /* PQgetvalue() has a value, check OID */
+ Oid oid = PQftype(res, j);
+ switch (oid)
+ {
case 3802: // JSON type hard coded in this example: jsonb
{
Document d;
@@ -994,7 +1010,9 @@ Document doc;
{
char *str = PQgetvalue(res, i, j);
if (oid == 1042) // char(x) rather than varchar so trim white space
+ {
str = trim(str);
+ }
Value value(str, allocator);
Value name(PQfname(res, j), allocator);
row.AddMember(name, value, allocator);
