Обсуждение: How to parse data type array columns?

Поиск
Список
Период
Сортировка

How to parse data type array columns?

От
Janning Vygen
Дата:
Hi,

if you use array data type in your database design and query your tables with
PHP you get a string which represents the array. It can look something like
this:

[1:2]{{"Hallo", "Te\"st},"},{"Hallo", "Test"}}

It can even have another delimiter than "," if you change the type delimiter.

Has anybody already written a function to parse this array into an php array
structure? A simple explode doesn't work of course. The list offers a too
simple explode(",", ereg_replace("{[-]}", $string)). this works only with one
level and numeric types.

Has anybody already written a recursive function to parse the array string?

kind regards,
Janning

Re: How to parse data type array columns?

От
Christopher Kings-Lynne
Дата:
Look at phpArray() in lib/classes/ADODB_base.pclass in the phpPgAdmin
3.5 source distribution.

It's not recursive - just parsed 1-d arrays.

Also doesn't support leading dimension indication.

Chris

Janning Vygen wrote:
> Hi,
>
> if you use array data type in your database design and query your tables with
> PHP you get a string which represents the array. It can look something like
> this:
>
> [1:2]{{"Hallo", "Te\"st},"},{"Hallo", "Test"}}
>
> It can even have another delimiter than "," if you change the type delimiter.
>
> Has anybody already written a function to parse this array into an php array
> structure? A simple explode doesn't work of course. The list offers a too
> simple explode(",", ereg_replace("{[-]}", $string)). this works only with one
> level and numeric types.
>
> Has anybody already written a recursive function to parse the array string?
>
> kind regards,
> Janning
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq


Re: How to parse data type array columns?

От
Greg Stark
Дата:
Janning Vygen <vygen@gmx.de> writes:

> Hi,
>
> if you use array data type in your database design and query your tables with
> PHP you get a string which represents the array. It can look something like
> this:
>
> [1:2]{{"Hallo", "Te\"st},"},{"Hallo", "Test"}}

Do you still get that if you use the binary format? I would expect it to be
easier to parse the binary format than this format which is really intended
for humans and dump files.

I think the right place to deal with this is down in the driver where it has
all the information about the types and can request the format it wants from
the database.

--
greg

Re: How to parse data type array columns?

От
Janning Vygen
Дата:
Am Dienstag, 16. August 2005 17:04 schrieb Greg Stark:
> Janning Vygen <vygen@gmx.de> writes:
> > Hi,
> >
> > if you use array data type in your database design and query your tables
> > with PHP you get a string which represents the array. It can look
> > something like this:
> >
> > [1:2]{{"Hallo", "Te\"st},"},{"Hallo", "Test"}}
>
> Do you still get that if you use the binary format? I would expect it to be
> easier to parse the binary format than this format which is really intended
> for humans and dump files.

What kind of "binary format" do you mean? anyway: In PHP you get it as a
string and i wonder if anyone has written a small pasrer function for php to
handle this string an convert it into an php array structure.

kind regards,
janning

Re: How to parse data type array columns?

От
Greg Stark
Дата:
Janning Vygen <vygen@gmx.de> writes:

> What kind of "binary format" do you mean? anyway: In PHP you get it as a
> string and i wonder if anyone has written a small pasrer function for php to
> handle this string an convert it into an php array structure.

The server can provide each data type in either ascii format or in a binary
representation. In general the binary representation is something that's
easier and more efficient to process by machine. I'm not sure what the array
representation looks like though.

I don't know whether the PHP driver uses binary representations for anything.
If it does it would make things like integers (imperceptibly) faster and
possibly slightly more reliable. In the case of arrays it would maybe make it
easier to code and maybe significantly more efficient.

It's possible it's already using binary mode for some data types and just
isn't for arrays. But I suspect it isn't.

--
greg

Re: How to parse data type array columns?

От
Christopher Kings-Lynne
Дата:
>>if you use array data type in your database design and query your tables with
>>PHP you get a string which represents the array. It can look something like
>>this:
>>
>>[1:2]{{"Hallo", "Te\"st},"},{"Hallo", "Test"}}
>
>
> Do you still get that if you use the binary format? I would expect it to be
> easier to parse the binary format than this format which is really intended
> for humans and dump files.
>
> I think the right place to deal with this is down in the driver where it has
> all the information about the types and can request the format it wants from
> the database.

I _really_ want to have an array parsing function in PHP...I'll have to
check if they query in binary mode or not...

Chris


Re: How to parse data type array columns?

От
"Joshua D. Drake"
Дата:
>
> I _really_ want to have an array parsing function in PHP...I'll have
> to check if they query in binary mode or not...


Google is your friend:


http://www.faqts.com/knowledge_base/view.phtml/aid/16852

>
> Chris
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend



Re: How to parse data type array columns?

От
Christopher Kings-Lynne
Дата:
> Google is your friend:
>
>
> http://www.faqts.com/knowledge_base/view.phtml/aid/16852

That's just the same as my existing 1-d array parser.  I mean one
written in C in the pgsql module that handles arbitrary arrays...

Chris


Re: How to parse data type array columns?

От
Janning Vygen
Дата:
Am Dienstag, 16. August 2005 22:08 schrieb Greg Stark:
> Janning Vygen <vygen@gmx.de> writes:
> > What kind of "binary format" do you mean? anyway: In PHP you get it as a
> > string and i wonder if anyone has written a small pasrer function for php
> > to handle this string an convert it into an php array structure.
>
> The server can provide each data type in either ascii format or in a binary
> representation. In general the binary representation is something that's
> easier and more efficient to process by machine. I'm not sure what the
> array representation looks like though.
>
> I don't know whether the PHP driver uses binary representations for
> anything. If it does it would make things like integers (imperceptibly)
> faster and possibly slightly more reliable. In the case of arrays it would
> maybe make it easier to code and maybe significantly more efficient.
>
> It's possible it's already using binary mode for some data types and just
> isn't for arrays. But I suspect it isn't.

Thanks for your great explanation, but in PHP you always get "strings" from
the PostgreSQL module. I guess even the integers are strings, but i am not
sure.

kind regards,
janning


Re: How to parse data type array columns?

От
Christopher Kings-Lynne
Дата:
> Thanks for your great explanation, but in PHP you always get "strings" from
> the PostgreSQL module. I guess even the integers are strings, but i am not
> sure.

Yep, everything's strings and NULLs.

Chris