array in a store procedure in C

Started by Juan Pablo Labout 11 years ago7 messagesgeneral
Jump to latest
#1Juan Pablo L
jpablolorenzetti@gmail.com

Hi, i m developing a store procedure that accepts an array of rows, this is
the simplified code:

http://pastebin.com/wC92Dh7f

Please note that i left out everything that is not related, in the
function, to the problem at hand, only the code related to my problem is
included.

The above does not allow me to access the members of the rows in the array,
this is how i call this function:

select ret,username,password from
wtt_add_account('2802021','JPL123','1','3',ARRAY[row('1','25','10')::wtt_balance_info_t,row('2','50','15')::wtt_balance_info_t]);

The type wtt_balance_info_t is:

CREATE TYPE wtt_balance_info_t AS (balanceid varchar(25),chgval
varchar(25),servicestop varchar(25)) .

I would really appreciate if someone could give me guidelines how to
read/extract the rows from the array and then get each element from the
rows. thank you very much!!

#2Michael Paquier
michael@paquier.xyz
In reply to: Juan Pablo L (#1)
Re: array in a store procedure in C

On Thu, Jan 29, 2015 at 11:45 PM, Juan Pablo L
<jpablolorenzetti@gmail.com> wrote:

I would really appreciate if someone could give me guidelines how to
read/extract the rows from the array and then get each element from the
rows. thank you very much!!

src/backend/utils/adt/array_userfuncs.c is a mine of information
containing a set of C functions to operate on arrays. You may as well
look at contrib/intarray for some inspiration.
--
Michael

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Juan Pablo L
jpablolorenzetti@gmail.com
In reply to: Michael Paquier (#2)
Re: array in a store procedure in C

i will look there ... i have been looking in a lot of source files and can
not find anything that helps but i will look in those specific files.
Thanks a lot.
On Jan 29, 2015 9:09 PM, "Michael Paquier" <michael.paquier@gmail.com>
wrote:

Show quoted text

On Thu, Jan 29, 2015 at 11:45 PM, Juan Pablo L
<jpablolorenzetti@gmail.com> wrote:

I would really appreciate if someone could give me guidelines how to
read/extract the rows from the array and then get each element from the
rows. thank you very much!!

src/backend/utils/adt/array_userfuncs.c is a mine of information
containing a set of C functions to operate on arrays. You may as well
look at contrib/intarray for some inspiration.
--
Michael

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Juan Pablo L (#3)
Re: array in a store procedure in C

On 1/29/15 10:53 PM, Juan Pablo L wrote:

i will look there ... i have been looking in a lot of source files and
can not find anything that helps but i will look in those specific
files. Thanks a lot.

You might find this shell script useful; it's meant to make it easy to
grep the entire codebase for some term. Note that the recursive grep
starts at the current directory, so make sure you're actually in the
pgsql source code when you use it.

cat ~/bin/pg_grep
#!/bin/sh

grep -r "$*" * | grep -iv TAGS: | grep -v 'Binary file' | grep -v '.deps/'
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#5Juan Pablo L
jpablolorenzetti@gmail.com
In reply to: Jim Nasby (#4)
Re: array in a store procedure in C

Thanks.
On Feb 2, 2015 8:58 PM, "Jim Nasby" <Jim.Nasby@bluetreble.com> wrote:

Show quoted text

On 1/29/15 10:53 PM, Juan Pablo L wrote:

i will look there ... i have been looking in a lot of source files and
can not find anything that helps but i will look in those specific
files. Thanks a lot.

You might find this shell script useful; it's meant to make it easy to
grep the entire codebase for some term. Note that the recursive grep starts
at the current directory, so make sure you're actually in the pgsql source
code when you use it.

cat ~/bin/pg_grep
#!/bin/sh

grep -r "$*" * | grep -iv TAGS: | grep -v 'Binary file' | grep -v '.deps/'
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

#6Noname
Holger.Friedrich-Fa-Trivadis@it.nrw.de
In reply to: Jim Nasby (#4)
Re: array in a store procedure in C

On Tuesday, February 03, 2015 3:58 AM, Jim Nasby wrote:

Note that the recursive grep starts at the current directory, so make sure you're actually in the pgsql source code when you use it.

cat ~/bin/pg_grep
#!/bin/sh

grep -r "$*" * | grep -iv TAGS: | grep -v 'Binary file' | grep -v '.deps/'

By the way, why not add a "cd" into the pgsql source tree to the script? That way you can't forget it when using the script...

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#7Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Noname (#6)
Re: array in a store procedure in C

On 2/3/15 7:03 AM, Holger.Friedrich-Fa-Trivadis@it.nrw.de wrote:

On Tuesday, February 03, 2015 3:58 AM, Jim Nasby wrote:

Note that the recursive grep starts at the current directory, so make sure you're actually in the pgsql source code when you use it.

cat ~/bin/pg_grep
#!/bin/sh

grep -r "$*" * | grep -iv TAGS: | grep -v 'Binary file' | grep -v '.deps/'

By the way, why not add a "cd" into the pgsql source tree to the script? That way you can't forget it when using the script...

Because I have multiple checkouts, and I don't always use the full tree
to search. It's a lot faster to only search the include directory, for
example.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general