Your query:
Select * from rpt.cst_data_integration_individuals(zone_id, period_start, period_end, is_child)
Implies that zone_id, etc are fields available. If this were within a stored procedure and those were variables, it would likely work, but as it stands in your query it doesn't even make sense.
You need to invoke parameters in your actual childrenQuery
with either the ':' or the '@' character.
Select * from rpt.cst_data_integration_individuals(:zone_id, :period_start, :period_end, :is_child)
Also, to help with debugging, declare your parameters explicitly with datatypes.
cmd.Parameters.Add(new NpgsqlParameter("zone_id", NpgsqlTypes.NpgsqlDbType.Integer));
cmd.Parameters.Add(new NpgsqlParameter("period_start", NpgsqlTypes.NpgsqlDbType.TimestampTz));
cmd.Parameters.Add(new NpgsqlParameter("period_end", NpgsqlTypes.NpgsqlDbType.TimestampTz));
cmd.Parameters.Add(new NpgsqlParameter("is_child", NpgsqlTypes.NpgsqlDbType.Boolean));
cmd.Parameters[0].Value = zoneId;
cmd.Parameters[1].Value = fromDate;
cmd.Parameters[2].Value = toDate;
cmd.Parameters[3].Value = true;
(There are golfed versions of the above, but I never bother -- I like the readabilty)
If you are using earlier version of Npgsql, they will probably be forgiving. If you are using recent version, they will give you a pretty clear error of where you went wrong. If zoneId
is an integer (and true
obviously matches a boolean datatype), then my guess would be there was a mismatch with how .NET sent the DateTime
datatype -- maybe it assumed it was a timestamp without time zone.
Either way, the explicit parameter declarations will help, whereas AddWithValue
is basically asking it to take its best guess.
Maybe for the time being avoid AddWithValue
. I'm not going to lie, I use it from time to time, but you really shoud limit its use.