Search Postgresql Archives

Re: PHP array to PlPgSQL arrat. How to?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/3/5 Dmitriy Igrishin <dmitigr@xxxxxxxxx>:
>
>
> 2011/3/5 Pavel Stehule <pavel.stehule@xxxxxxxxx>
>>
>> 2011/3/5 Dmitriy Igrishin <dmitigr@xxxxxxxxx>:
>> >
>> >
>> > 2011/3/5 Pavel Stehule <pavel.stehule@xxxxxxxxx>
>> >>
>> >> 2011/3/5 Andre Lopes <lopes80andre@xxxxxxxxx>:
>> >> > Hi Pavel,
>> >> >
>> >> > Thanks for the reply.
>> >> >
>> >> > In PlpgSQL there is possible to define arrays with "Key => Value, Key
>> >> > =>
>> >> > Value"?
>> >> >
>> >>
>> >> No, no directly
>> >>
>> >> there are no hash array
>> >>
>> >> there is a workaround a hstore module
>> >
>> > Why hstore is a workaround ? hstore is a proven and
>> > mature module.
>> > And since 9.0 is has a lot of improvements and
>> > make the life easy in some cases today and here.
>>
>> It doesn't allow a nested hstore values.
>
> How so ?
>
> dmitigr=> select ('id=>1, dat=>"id=>100"'::hstore -> 'dat')::hstore->'id'
> id;
> Âid
> -----
> Â100
> (1 row)

you cannot do some like

'a => { aa=>1, ba=>2}, c=>10, d => { a => 11, b => 12}'::hstore

your solution is trick, but it doesn't help too much with
deserialisation of PHP serialised structured value.

I have nothing against hstore - it's best for substitution of EAV and
good for almost all database use cases. But it hasn't a functionality
of hash tables from Perl or PHP.

Regards

Pavel

>
>>
>> Regards
>>
>> Pavel
>>
>>
>> >>
>> >> http://www.postgresql.org/docs/9.0/static/hstore.html
>> >>
>> >> attention - it doesn't allow a nested values
>> >>
>> >> Regards
>> >>
>> >> Pavel Stehule
>> >>
>> >> for more complex values is other was - using a temp tables - you can
>> >> fill a temp table and in next step a plpgsql code use this temp table.
>> >> But it should have a performance impacts.
>> >>
>> >>
>> >>
>> >> > Best Regards,
>> >> >
>> >> >
>> >> > On Sat, Mar 5, 2011 at 7:28 PM, Pavel Stehule
>> >> > <pavel.stehule@xxxxxxxxx>
>> >> > wrote:
>> >> >> Hello
>> >> >>
>> >> >> there isn't a simple way :(
>> >> >>
>> >> >> the most simply way is using string_to_array function
>> >> >>
>> >> >> SELECT func(string_to_array('1,2,3,4,5',','));
>> >> >>
>> >> >> Regards
>> >> >>
>> >> >> Pavel Stehule
>> >> >>
>> >> >>
>> >> >> 2011/3/5 Andre Lopes <lopes80andre@xxxxxxxxx>:
>> >> >>> Hi,
>> >> >>>
>> >> >>> I need to transform an PHP array to an PlPgSQL array. The PHP array
>> >> >>> is
>> >> >>> like this:
>> >> >>>
>> >> >>> [quote]
>> >> >>> $arr = array(
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0 => array(
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"base64" =>
>> >> >>> "ddfffffff",
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"image_type"
>> >> >>> =>
>> >> >>> "jpg",
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"width" =>
>> >> >>> "343",
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"height" =>
>> >> >>> "515",
>> >> >>>
>> >> >>> Â"html_width_height" => 'width="343" height="515"',
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"mime" =>
>> >> >>> "image/jpeg"
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â),
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â1 => array(
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"base64" =>
>> >> >>> "ddfffffffddddd",
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"image_type"
>> >> >>> =>
>> >> >>> "jpg",
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"width" =>
>> >> >>> "343",
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"height" =>
>> >> >>> "515",
>> >> >>>
>> >> >>> Â"html_width_height" => 'width="343" height="515"',
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"mime" =>
>> >> >>> "image/jpeg"
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â)
>> >> >>> Â Â Â Â Â Â Â Â Â Â Â Â);
>> >> >>> [/quote]
>> >> >>>
>> >> >>> How can I pass this kinf of PHP array to PlPgSQL?
>> >> >>>
>> >> >>> Give me a clue.
>> >> >>>
>> >> >>> Best Regards,
>> >> >>>
>> >> >>> --
>> >> >>> Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
>> >> >>> To make changes to your subscription:
>> >> >>> http://www.postgresql.org/mailpref/pgsql-general
>> >> >>>
>> >> >>
>> >> >
>> >>
>> >> --
>> >> Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
>> >> To make changes to your subscription:
>> >> http://www.postgresql.org/mailpref/pgsql-general
>> >
>> >
>> >
>> > --
>> > // Dmitriy.
>> >
>> >
>> >
>
>
>
> --
> // Dmitriy.
>
>
>

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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux