How to parse data type array columns?
How to parse data type array columns?
am 16.08.2005 10:04:07 von 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
---------------------------(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?
am 16.08.2005 10:42:53 von 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
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Re: How to parse data type array columns?
am 16.08.2005 17:04:20 von Greg Stark
Janning Vygen 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
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
Re: How to parse data type array columns?
am 16.08.2005 20:25:16 von Janning Vygen
Am Dienstag, 16. August 2005 17:04 schrieb Greg Stark:
> Janning Vygen 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
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Re: How to parse data type array columns?
am 16.08.2005 22:08:01 von Greg Stark
Janning Vygen 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
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?
http://archives.postgresql.org
Re: How to parse data type array columns?
am 17.08.2005 04:19:11 von 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
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
Re: How to parse data type array columns?
am 17.08.2005 04:40:40 von Joshua 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
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
Re: How to parse data type array columns?
am 17.08.2005 05:00:30 von 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
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Re: How to parse data type array columns?
am 17.08.2005 09:12:14 von Janning Vygen
Am Dienstag, 16. August 2005 22:08 schrieb Greg Stark:
> Janning Vygen 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
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
Re: How to parse data type array columns?
am 17.08.2005 09:22:40 von 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
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend