[GENERAL] Associative array in Pl/PgSQL

2013-05-04 Thread Karel Riveron Escobar
Hello everyone,


I have a problem with Pl/PgSQL function. I need to pass it as parameter an 
associative array. I have no idea how to do that. C an s omebody help me?


To be more specific, I have an associative array in PHP. Something like this:



array(
'name' => 'Robert',
'age' => 24,
'teachers' => array(
array( 'name'=>'Sean'),
array('name'=>'Megan')
)
);


And, I need work with it into a Pl/PgSQL function. How can I do this?


Thanks in advance.


Regards, Karel Riverón
Student Scientific Council
Informatics Science University

http://www.uci.cu



Re: [GENERAL] Associative array in Pl/PgSQL

2013-05-04 Thread John R Pierce

On 5/4/2013 4:40 PM, Karel Riveron Escobar wrote:

And, I need work with it into a Pl/PgSQL function. How can I do this?


SQL has no such concept as 'associative arrays'.  it understands 
relations (tables).


maybe convert it to hstore format, and pass it in as a text string, but 
your example gets even messier in that you've nested these associative 
things.


would be much more appropriate to store that data as tables in postgresql.



--
john r pierce  37N 122W
somewhere on the middle of the left coast



Re: [GENERAL] Simple SQL INSERT to avoid duplication failed: why?

2013-05-04 Thread Jasen Betts
On 2013-05-01, Carlo Stonebanks  wrote:
> There are no client poolers (unless pgtcl has one I don't know about) so
> this is unlikely. 
>
> The trigger is an interesting idea to try if it happens again - I can't keep
> it for long as it is for a massive cache (used to deflect calls to a web
> service) and will bloat the logs pretty quickly.
>
> I have to ask myself, is it more likely that I have discovered some PG
> anomaly in 9.0 that no one has ever noticed, or that the client has
> accidentally launched the process twice and doesn't know it?

If it's running on a web server and two clients send the same request
simultaneously could that cause it to try the same task twice
simultaneously?

-- 
⚂⚃ 100% natural



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


Re: [GENERAL] Associative array in Pl/PgSQL

2013-05-04 Thread Karel Riveron Escobar
John:

Thanks for reply so fast. I think that store my data as tables will be the best.

Thanks again.

Regards, Karel Riverón
Student Scientific Council
Informatics Science University
- Original Message -

| From: "John R Pierce" 
| To: pgsql-general@postgresql.org
| Sent: Saturday, May 4, 2013 7:50:57 PM
| Subject: Re: [GENERAL] Associative array in Pl/PgSQL

| On 5/4/2013 4:40 PM, Karel Riveron Escobar wrote:

| | And, I need work with it into a Pl/PgSQL function. How can I do
| | this?
|
| SQL has no such concept as 'associative arrays'. it understands
| relations (tables).

| maybe convert it to hstore format, and pass it in as a text string,
| but your example gets even messier in that you've nested these
| associative things.

| would be much more appropriate to store that data as tables in
| postgresql.

| --
| john r pierce  37N 122W
| somewhere on the middle of the left coast

http://www.uci.cu



Re: [GENERAL] Associative array in Pl/PgSQL

2013-05-04 Thread Jasen Betts
On 2013-05-04, Karel Riveron Escobar  wrote:
> --=_be60f7f0-365e-4e0a-98b5-f8b13a8ea728
> Content-Type: text/plain; charset=utf-8
> Content-Transfer-Encoding: quoted-printable
>
> Hello everyone, 
>
>
> I have a problem with Pl/PgSQL function. I need to pass it as parameter an =
> associative array. I have no idea how to do that. C an s omebody help me? 
>
>
> To be more specific, I have an associative array in PHP. Something like thi=
> s: 

 [...]

> And, I need work with it into a Pl/PgSQL function. How can I do this? 

possibly this can be done using hstore and/or JSON



-- 
⚂⚃ 100% natural



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


Re: [GENERAL] Associative array in Pl/PgSQL

2013-05-04 Thread Darren Duncan

On 2013.05.04 4:40 PM, Karel Riveron Escobar wrote:

Hello everyone,

I have a problem with Pl/PgSQL function. I need to pass it as parameter an
associative array. I have no idea how to do that. Can somebody help me?

To be more specific, I have an associative array in PHP. Something like this:

array(
  'name' => 'Robert',
  'age' => 24,
  'teachers' => array(
array('name'=>'Sean'),
array('name'=>'Megan')
 )
);

And, I need work with it into a Pl/PgSQL function. How can I do this?


The answer to your question depends on a number of factors about the structure 
of your associative array.


If the structure is heterogeneous, where each element might be a different data 
type, and if the keys of your array are all text analogous to attribute names, 
then a SQL tuple/row is the most direct analogy, so use some ROW type with one 
attribute per associative array element.


Conversely, if the structure is homogeneous, where all elements have the same 
key types and same value types, then a binary/2-attribute/column relation/table 
is the most direct analogy, so then use a TABLE(key text,value whatever) type.


From your example though, it looks like a ROW is definitely what you want.

-- Darren Duncan



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