Is there a way to distinguish Empty String from NULL in db_postgres?
The docs mention that """... NULL database values will be converted to nil ...""", but it seems like it's not always working.
In the example below there are 2 strange things:
import postgres, db_postgres, strutils, sequtils
let conn = open("localhost:5432", "postgres", "", "nim_test")
let batch = """
drop table if exists test_users;
create table test_users(
name varchar(100) not null,
nick varchar(100)
);
insert into test_users (name, nick) values ('Jim', null)
"""
for part in batch.split(";"): conn.exec(sql(part))
var columns: DbColumns
for row in conn.instantRows(columns, sql("select name, nick from test_users")):
echo columns[0].typ.notNull # ==> false <- Error, should be true
echo columns[1].typ.notNull # ==> false
echo row[0] # ==> "Jim"
echo row[1] # ==> "" <- Error, should be nil
I have a similar question, for the following statement:
db.exec(sql"insert into data (name) values (?)", name)
the name field could be a string value or null, what is the best way to deal with it?