Search code examples
vb.netnpgsql

Passing multi-line text parameter from VB.NET to npgsql


I have a working Postgres function that take a multi-line text parameter "_list" and uses regexp_split_to_table(TRIM(_list), '\r\n') to create a table with each line of text as a row.

I now want to call this from VB.NET reading the value from a textarea. I am using pgCmd.Parameters.AddWithValue("_list", NpgsqlDbType.Text, my_list).

However VB is replacing the linebreaks with vbLF and my Postgres function is seeing it as a single line. How do I get around this?


Solution

  • regex_split_to_table looks to take a regex as its split matcher..

    ..so just make it regexp_split_to_table(TRIM(_list), '\r?\n') (added a question mark after \r) so that it matches 0 or 1 carriage returns followed by a line feed when splitting. This way it doesn't matter if your program, or any other program, supplies CRLF or LF..