Re: Question about array datatype, and alternatives
От | John DeSoi |
---|---|
Тема | Re: Question about array datatype, and alternatives |
Дата | |
Msg-id | E01FCA4C-D6E8-4585-A408-50345195BDC5@pgedit.com обсуждение исходный текст |
Ответ на | Question about array datatype, and alternatives (Lynna Landstreet <lynna@spidersilk.net>) |
Список | pgsql-php |
On May 9, 2007, at 1:04 AM, Lynna Landstreet wrote: > My first thought was that I could use the much-maligned array > datatype, and > just dump the entire array they send back into one column. But > having looked > through the documentation on that datatype, I'm not so sure that > would work > for an array of uncertain size. It looks as though it's meant to > handle > arrays that are a little more predictable in their composition. Now, > phpPgAdmin does list a datatype called "anyarray", which according > to the > documentation is a "polymorphous" datatype that can handle almost > anything, > but there isn't a lot of detail on how to use that. PostgreSQL's array > syntax seems to be very different from PHP's, and I don't know if it's > really feasible to just dump the entire contents of a PHP > associative array > into an anyarray column. I think you might have misread misread the documentation. You don't have to declare the size of the array in your schema specification (e.g. you can declare a column as text[] or text[][]). The catch to using arrays is that they don't map directly from PHP to PostgreSQL. So you have to write a small amount of code to format your PHP array as a PostgreSQL array string. > > So then I thought of just serializing the array to result in a > single string > - would that work better? A PostgreSQL array might be better if you plan to query the data or use it in some way outside of PHP. If you only intend to use the value in PHP, it is much easier to serialize it and stuff it in a text column. John John DeSoi, Ph.D. http://pgedit.com/ Power Tools for PostgreSQL
В списке pgsql-php по дате отправления: