pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedArray fundamentals
3+ messages / 3 participants
[nested] [flat]
* Array fundamentals
@ 2012-06-02 17:05 idc danny <idcdanny@yahoo.com>
0 siblings, 2 replies; 3+ messages in thread
From: idc danny @ 2012-06-02 17:05 UTC (permalink / raw)
To: pgsql-performance
Hi all,
I got 2 complementary functions, which will do opposite things.
1 - CombineStrings(stringarray character varying[]) RETURNS character varying
This one will take as parameter an array of strings and will return a string with some formatted information inside
2- SplitString2Array(stringtosplit character varying) RETURNS character varying[]
This one will take as parameter a formatted string and will return an array of string
The following is true, both works just fine :
select SplitString2Array(CombineStrings(ARRAY['abba', 'queen']))
will return {'abba', 'queen'}
Now, if I want do do the following:
select CombineStrings(ARRAY[SplitString2Array("SomeTextColumn"), 'New string to add']) from "SomeTable"
i get the following error:
array value must start with "{" or dimension information
What am I doing wrong, I am feeling I still don't get the array fundamentals. My goal is to add to inside formatted information in the column "SomeTextColumn" my new string 'New string to add' in the same manner if I would been used the following:
Insert into "SomeTable"("SomeTextColumn") values (CombineString(ARRAY['abba', 'queen', 'New string to add']))
Thank you in advance,
Danny
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [PERFORM] Array fundamentals
@ 2012-06-02 17:21 Jeff Davis <pgsql@j-davis.com>
parent: idc danny <idcdanny@yahoo.com>
1 sibling, 0 replies; 3+ messages in thread
From: Jeff Davis @ 2012-06-02 17:21 UTC (permalink / raw)
To: idc danny <idcdanny@yahoo.com>; +Cc: pgsql-general@postgresql.org
On Sat, 2012-06-02 at 10:05 -0700, idc danny wrote:
> Now, if I want do do the following:
> select CombineStrings(ARRAY[SplitString2Array("SomeTextColumn"), 'New
> string to add']) from "SomeTable"
>
> i get the following error:
> array value must start with "{" or dimension information
This discussion is better suited to another list, like -general, so I'm
moving it there.
In the fragment:
ARRAY[SplitString2Array("SomeTextColumn"), 'New string to add']
The first array element is itself an array of strings, but the second is
a plain string. Array elements must all be the same type.
What you want to do is replace that fragment with something more like:
array_append(SplitString2Array("SomeTextColumn"), 'New string to add')
If that still doesn't work, we'll need to see the exact definitions of
your functions.
Also, as a debugging strategy, I recommend that you look at the pieces
that do work, and slowly build up the fragments until it doesn't work.
That will allow you to see the inputs to each function, and it makes it
easier to see why it doesn't work.
Regards,
Jeff Davis
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Array fundamentals
@ 2012-07-18 19:32 Robert Haas <robertmhaas@gmail.com>
parent: idc danny <idcdanny@yahoo.com>
1 sibling, 0 replies; 3+ messages in thread
From: Robert Haas @ 2012-07-18 19:32 UTC (permalink / raw)
To: idc danny <idcdanny@yahoo.com>; +Cc: pgsql-performance
On Sat, Jun 2, 2012 at 1:05 PM, idc danny <idcdanny@yahoo.com> wrote:
> Hi all,
> I got 2 complementary functions, which will do opposite things.
> 1 - CombineStrings(stringarray character varying[]) RETURNS character
> varying
> This one will take as parameter an array of strings and will return a string
> with some formatted information inside
> 2- SplitString2Array(stringtosplit character varying) RETURNS character
> varying[]
> This one will take as parameter a formatted string and will return an array
> of string
>
> The following is true, both works just fine :
> select SplitString2Array(CombineStrings(ARRAY['abba', 'queen']))
> will return {'abba', 'queen'}
>
> Now, if I want do do the following:
> select CombineStrings(ARRAY[SplitString2Array("SomeTextColumn"), 'New string
> to add']) from "SomeTable"
> i get the following error:
> array value must start with "{" or dimension information
>
> What am I doing wrong, I am feeling I still don't get the array
> fundamentals. My goal is to add to inside formatted information in the
> column "SomeTextColumn" my new string 'New string to add' in the same manner
> if I would been used the following:
> Insert into "SomeTable"("SomeTextColumn") values
> (CombineString(ARRAY['abba', 'queen', 'New string to add']))
It sounds like one or both of your functions have a bug in them, but
without knowing what they're supposed to do or seeing the source code,
it's pretty hard to guess what it might be.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2012-07-18 19:32 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-06-02 17:05 Array fundamentals idc danny <idcdanny@yahoo.com>
2012-06-02 17:21 ` Jeff Davis <pgsql@j-davis.com>
2012-07-18 19:32 ` Robert Haas <robertmhaas@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox