pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to parse data type array columns?
10+ messages / 4 participants
[nested] [flat]
* How to parse data type array columns?
@ 2005-08-16 08:04 Janning Vygen <vygen@gmx.de>
0 siblings, 2 replies; 10+ messages in thread
From: Janning Vygen @ 2005-08-16 08:04 UTC (permalink / raw)
To: pgsql-php
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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: How to parse data type array columns?
@ 2005-08-16 08:42 Christopher Kings-Lynne <chriskl@familyhealth.com.au>
parent: Janning Vygen <vygen@gmx.de>
1 sibling, 0 replies; 10+ messages in thread
From: Christopher Kings-Lynne @ 2005-08-16 08:42 UTC (permalink / raw)
To: Janning Vygen <vygen@gmx.de>; +Cc: pgsql-php
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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: How to parse data type array columns?
@ 2005-08-16 15:04 Greg Stark <gsstark@mit.edu>
parent: Janning Vygen <vygen@gmx.de>
1 sibling, 2 replies; 10+ messages in thread
From: Greg Stark @ 2005-08-16 15:04 UTC (permalink / raw)
To: Janning Vygen <vygen@gmx.de>; +Cc: pgsql-php
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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: How to parse data type array columns?
@ 2005-08-16 18:25 Janning Vygen <vygen@gmx.de>
parent: Greg Stark <gsstark@mit.edu>
1 sibling, 1 reply; 10+ messages in thread
From: Janning Vygen @ 2005-08-16 18:25 UTC (permalink / raw)
To: pgsql-php; +Cc: Greg Stark <gsstark@mit.edu>
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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: How to parse data type array columns?
@ 2005-08-16 20:08 Greg Stark <gsstark@mit.edu>
parent: Janning Vygen <vygen@gmx.de>
0 siblings, 1 reply; 10+ messages in thread
From: Greg Stark @ 2005-08-16 20:08 UTC (permalink / raw)
To: Janning Vygen <vygen@gmx.de>; +Cc: pgsql-php@postgresql.org, Greg Stark <gsstark@mit.edu>
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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: How to parse data type array columns?
@ 2005-08-17 02:19 Christopher Kings-Lynne <chriskl@familyhealth.com.au>
parent: Greg Stark <gsstark@mit.edu>
1 sibling, 1 reply; 10+ messages in thread
From: Christopher Kings-Lynne @ 2005-08-17 02:19 UTC (permalink / raw)
To: Greg Stark <gsstark@mit.edu>; +Cc: Janning Vygen <vygen@gmx.de>; pgsql-php
>>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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: How to parse data type array columns?
@ 2005-08-17 02:40 Joshua D. Drake <jd@commandprompt.com>
parent: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
0 siblings, 1 reply; 10+ messages in thread
From: Joshua D. Drake @ 2005-08-17 02:40 UTC (permalink / raw)
To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: Greg Stark <gsstark@mit.edu>; Janning Vygen <vygen@gmx.de>; pgsql-php
>
> 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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: How to parse data type array columns?
@ 2005-08-17 03:00 Christopher Kings-Lynne <chriskl@familyhealth.com.au>
parent: Joshua D. Drake <jd@commandprompt.com>
0 siblings, 0 replies; 10+ messages in thread
From: Christopher Kings-Lynne @ 2005-08-17 03:00 UTC (permalink / raw)
To: Joshua D. Drake <jd@commandprompt.com>; +Cc: Greg Stark <gsstark@mit.edu>; Janning Vygen <vygen@gmx.de>; pgsql-php
> 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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: How to parse data type array columns?
@ 2005-08-17 07:12 Janning Vygen <vygen@gmx.de>
parent: Greg Stark <gsstark@mit.edu>
0 siblings, 1 reply; 10+ messages in thread
From: Janning Vygen @ 2005-08-17 07:12 UTC (permalink / raw)
To: pgsql-php; +Cc: Greg Stark <gsstark@mit.edu>
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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: How to parse data type array columns?
@ 2005-08-17 07:22 Christopher Kings-Lynne <chriskl@familyhealth.com.au>
parent: Janning Vygen <vygen@gmx.de>
0 siblings, 0 replies; 10+ messages in thread
From: Christopher Kings-Lynne @ 2005-08-17 07:22 UTC (permalink / raw)
To: Janning Vygen <vygen@gmx.de>; +Cc: pgsql-php@postgresql.org, Greg Stark <gsstark@mit.edu>
> 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
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2005-08-17 07:22 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-16 08:04 How to parse data type array columns? Janning Vygen <vygen@gmx.de>
2005-08-16 08:42 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-08-16 15:04 ` Greg Stark <gsstark@mit.edu>
2005-08-16 18:25 ` Janning Vygen <vygen@gmx.de>
2005-08-16 20:08 ` Greg Stark <gsstark@mit.edu>
2005-08-17 07:12 ` Janning Vygen <vygen@gmx.de>
2005-08-17 07:22 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-08-17 02:19 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-08-17 02:40 ` Joshua D. Drake <jd@commandprompt.com>
2005-08-17 03:00 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox