I have the following function in my Postgres Database
CREATE OR REPLACE FUNCTION "thisSearchList"(IN searchstring text)
RETURNS TABLE(q_description text, q_barcode text) AS
$BODY$
SELECT q_description, q_barcode
FROM q_product
WHERE q_description like $1
OR q_barcode like $1
$BODY$
LANGUAGE sql VOLATILE
COST 100
ROWS 1000;
In my C# code I have the following code to utilize said function
NpgsqlConnection connection = new NpgsqlConnection("Host=192.168.0.52;Database=bolo;Username=western;Password=western");
connection.Open(); /*OPEN DATABASE CONNECTION*/
NpgsqlCommand cmd = new NpgsqlCommand("thisSearchList", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@string", NpgsqlTypes.NpgsqlDbType.Text);
cmd.Parameters["@string"].Value = searchValue.ToUpper();
NpgsqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
var prod = new ProductViewModel();
prod.q_description = dr["q_description"].ToString();
prod.q_barcode = dr["q_barcode"].ToString();
model.Add(prod);
}
On running the application - user types in search textbox and clicks search to trigger the function and return a list of products to display on view/page: I get the following error
42883: function thissearchlist(string := text) does not exist
with the source at
NpgsqlDataReader dr = cmd.ExecuteReader();
From my understanding through googling, Postgres might have an issue with strings and text!? Where its looking for a function that had a parameter string rather than text as defined in db (can only define text (not string) in postgres). But then wouldnt this line
cmd.Parameters.Add("@string", NpgsqlTypes.NpgsqlDbType.Text);
would have solved the issue when passing the parameter with the function, so it gets the appropriate function (with text parameter) when called? What am I missing at this point, or its not not possible to call postgres functions this way?