Imagine that I have a table t1: col1: varchar(255)
, col2: boolean DEFAULT true
and I created this prepared statement p1: INSERT INTO t1(col1,col2) VALUES ($1,$2)
and in GO I am executing my prepared statement but based on condition1 I want to pass the DEFAULT
keyword to the second parameter in the prepared statement i.e
if condition1 {
sql.Exec(p1,"FOO","DEFAULT") // but this returns an error: invalid input syntax for type boolean: "DEFAULT"
} else{
//pass other parameters to the prepared statement
}
summary: I am trying to end with this sql statement:
INSERT INTO t1(col1,col2) VALUES ('FOO',DEFAULT)
but I am getting this:
INSERT INTO t1(col1,col2) VALUES ('FOO','DEFAULT') //quotations on DEFAULT
anybody knows how can I solve this?
I think it would be better, since you already have an if/else detecting the situation where you don't have a value to pass, to instead do
INSERT INTO t1 (col1) VALUES ('FOO');
and let postgres use the default value for the other column.