1

Currently, When I pass an empty string in VoltDB Stored Procedure parameter, It stores as an empty string. Is there any way to store NULL when I pass an empty string as a parameter(Just Like Oracle)?

c.sankhala
  • 850
  • 13
  • 27

1 Answers1

1

In VoltDB, empty strings are not the same thing as NULL. Oracle is the only database I know that considers these equal. You can simply pass NULL into a VoltDB stored procedure if you wish to store NULL.

If you want an empty string to be stored as NULL, I think the best way to do this would be a conditional statement in some java stored procedure code. If the input is "", then store null. Like so:

public class Example extends VoltProcedure {

    public final SQLStmt sql = new SQLStmt(
        "INSERT INTO t (col1, col2) VALUES (?,?);");

    public VoltTable[] run(long id, String val) throws VoltAbortException {

        if (val.equals("")) {
            val = null;
        }

        voltQueueSQL( sql, id, val );
        return voltExecuteSQL();

    }
}
Andrew
  • 311
  • 1
  • 8