pass array to postgresql problem after package update
See original GitHub issueused the following code
C#
List<List<string>> items = new List<List<string>>();
foreach (OrderItemsDTO p in products)
{
List<string> list = new List<string>();
list.Add(p.product_id.ToString());
list.Add(Convert.ToString(p.quantity, culture));
list.Add(Convert.ToString(p.price, culture));
list.Add(Convert.ToString(p.discount, culture));
list.Add(Convert.ToString(p.total, culture));
list.Add(Convert.ToString(p.cost, culture));
list.Add(p.User.id.ToString());
list.Add(p.order.ToString());
items.Add(list);
}
command.Parameters.Add(null, NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Varchar).Value = items.ToArray();
POSTGRESQL
CREATE OR REPLACE FUNCTION public.insert_request(
_character varying products[])
RETURNS integer
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
THE $BODY$
declare
it worked perfectly, but after I updated the Npgsql.dll package from version 2.0.12.0 to version 5.07.0, it crashed and returned the following error:
While trying to write an array, one of its elements failed validation. You may be trying to mix types in a non-generic IList, or to write a jagged array.
I can’t solve it at all.
The function in postgresql is working normally, the problem is in passing the parameters.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Passing json containing array of objects to PostgreSQL ...
The problem was with the syntax inside the function. The correct syntax for parsing array of objects and assigning it to json ARRAY:...
Read more >How to pass a table type with an array field to a function in ...
Your function looks a bit overcomplicated for me, but anways. An array literal must be enclosed by single quotes, so try the following:...
Read more >Documentation: 15: 43.6. Control Structures
If WHEN is specified, the next iteration of the loop is begun only if boolean-expression is true. Otherwise, control passes to the statement...
Read more >Using Arrays in PostgreSQL: A Guide
With the array, PostgreSQL allows columns of a table to be defined as variable-length multidimensional arrays.
Read more >PostgreSQL — SQLAlchemy 2.0 Documentation
When SQLAlchemy issues a single INSERT statement, to fulfill the contract of having the “last insert identifier” available, a RETURNING clause is added...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@roji muito obrigado, graças a você conseguir resolver o problema, acredite, parece besteira mas já tinha perdido um bom tempo tentando resolver.
Segue resolução.
In this case, I have to pass an array of fixed dimensions. Right? but the problem is there, the matrix has to be dynamic, because the amount of products can vary, the fields will always be the same but the amount of lines is variable. So the List<List<string>> was serving me well.