Обсуждение: Array value from table as parameter
Hi,
I need to pass an array as a parameter in a function, but it is a part of a trigger that get a "new" value.
I've tested it like
select function_x(10000,555555,array[['xxxxx'],['yyyyy']])
or
select function_x(10000,555555,array[['xxxxx','yyyyy']])
and it worked.
But if I use
select function_x(10000,555555,new.situations)
it doesn't work, as the value comes like this: {"xxxxx","yyyyy"}
I couldn't find a function that converts {} values back to [] without treat it as a string and use replace, what I think that is not the ideal solution because it may can't satisfy more complex arrays.
Regards,
Aislan Luiz Wendling
it doesn't work, as the value comes like this: {"xxxxx","yyyyy"}
SELECT '{"xxxxx","yyyyy"}'::text[] = array['xxxxx','yyyyy']::text[]; -- TRUE
David J.
Hello
> From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Aislan Luiz
Wendling
> Sent: Mittwoch, 20. Juli 2016 19:17
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] Array value from table as parameter
>
> Hi,
>
> I need to pass an array as a parameter in a function, but it is a part of a trigger that get a "new" value.
>
> I've tested it like
>
> select function_x(10000,555555,array[['xxxxx'],['yyyyy']])
> or
> select function_x(10000,555555,array[['xxxxx','yyyyy']])
>
> and it worked.
>
> But if I use
>
> select function_x(10000,555555,new.situations)
>
> it doesn't work, as the value comes like this: {"xxxxx","yyyyy"}
> I couldn't find a function that converts {} values back to [] without treat it as a string and use replace, what I
thinkthat is
not the ideal solution because it may can't satisfy more complex arrays.
Would it help to simply cast the argument to TEXT[]?
select function_x(10000,555555,(new.situations)::TEXT[]);
I am not sure if the extra parenthesis are necessary.
Regards
Charles
On 7/22/16 7:31 AM, Charles Clavadetscher wrote:
>> I need to pass an array as a parameter in a function, but it is a part of a trigger that get a "new" value.
>> >
>> > I've tested it like
>> >
>> > select function_x(10000,555555,array[['xxxxx'],['yyyyy']])
>> > or
>> > select function_x(10000,555555,array[['xxxxx','yyyyy']])
>> >
>> > and it worked.
>> >
>> > But if I use
>> >
>> > select function_x(10000,555555,new.situations)
>> >
>> > it doesn't work, as the value comes like this: {"xxxxx","yyyyy"}
>> > I couldn't find a function that converts {} values back to [] without treat it as a string and use replace, what I
thinkthat is
> not the ideal solution because it may can't satisfy more complex arrays.
>
> Would it help to simply cast the argument to TEXT[]?
That would simply be masking the problem.
'{"xxxxx","yyyyy"}' is a completely valid representation of an array,
but not one you should be getting out of code (because there's no reason
for array_out to toss the extra "s in there). It also doesn't match
either of your other examples.
Please create a stand-alone scenario that demonstrates the problem
you're seeing. I suspect that in the process of doing that you're going
to uncover a bug in your code, but if not then we'll have something
concrete we can look at.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532) mobile: 512-569-9461