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:

  * The definition of column doesn't indicate if it's nullable or not.
  * Empty `empty string` returned as a value instead of `nil`.


    
    
    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
    
    
    Run

Reply via email to