Closed gabrieligbastos closed 2 months ago
Postgres does not have a concept of TEXT[][]
- TEXT[]
is the only array type for TEXT
values.
ok, but, considering this, how can i send it as text[] only without the quotes?
i mean, if i send via DataGrip:
SELECT * FROM public.check_parameter_2('{{"should_fail_at_6","false"},{"should_fail_at_9","false"},{"should_fail_at_7","false"},{"should_fail_at_8","false"},{"should_fail_at_11","false"},{"should_fail_at_3","true"},{"should_fail_at_2","false"},{"should_fail_at_5","false"},{"should_fail_at_10","false"},{"should_fail_at_4","false"}}'::TEXT[]);
it works. I need to somehow send the string { {..}, {..}, {..} } as string, casting to TEXT[] but everything i try at most send this: { "{...}, {...}, {...}" }
How to avoid this extra inner quotes? Any clue?
I used TEXT[][] based on some usages on postgresql doc
From:
https://www.postgresql.org/docs/current/arrays.html
CREATE TABLE sal_emp (
name text,
pay_by_quarter integer[],
schedule text[][]
);
The postgres array type is multidimensional. This test case builds a 2x2 array for example: https://github.com/sfackler/rust-postgres-array/blob/master/src/lib.rs#L98-L106
From that page:
Arrays of a particular element type are all considered to be of the same type, regardless of size or number of dimensions. So, declaring the array size or number of dimensions in CREATE TABLE is simply documentation; it does not affect run-time behavior.
Ohh wow, thanks @sfackler I think now i totally got it..
let mut array = Array::from_vec(vec![], 0);
// array.wrap(0);
for item in payload.0.iter() {
if array.iter().len() == 0 {
array = Array::from_vec(vec![item.0.to_string(), item.1.to_string()], 1);
array.wrap(1);
}
else {
array.push(Array::from_vec(vec![item.0.to_string(), item.1.to_string()], 1));
}
}
This one is the one working for me, as you mentioned, wrapping the dimensions. My code is considering lower_bound 1 to default on db, so got this little bug that was fixed with lower_bound = 1.
Thanks so much :)
I have a function like:
I tried a lot of different things to make the rust call it and it works. The final workaround was to create a wrapper like:
Any solution to make it able to call directly? Some of things i tried, first i created a own class extending HashMap
Then i implemented ToSql in it, trying some options, the first was:
This it was saying the max lenght (293838793) of array was higher than the (6) allowed. Then i tried, using this repo as base, to implement a custom array writer
something like this, but it was either saying that im trying to send array of type that was not expected, or it sends but getting all null, because it when send it was wrapping my data into quotes, so could never make it work.
i realized from postgres_rust that they are serializing with the string binary protocol. so i changed to:
Then i got problem of types, because as postgres, even creating my function as TEXT[][], it creates it as TEXT[], and then even defining on rust TEXT[][], it is calling ToSql as _text. So getting the error:
And then if i try to send
it will be send with the old quotes, so wont work too. any help on this so i get rid of the workaround function? thanks