Skip site navigation (1) Skip section navigation (2)

Re: populating arrays with default values

From: Decibel! <decibel(at)decibel(dot)org>
To: "G(dot) J(dot) Walsh" <gjwalsh(at)dscdirectionalservices(dot)com>,pgsql-novice(at)postgresql(dot)org
Subject: Re: populating arrays with default values
Date: 2007-11-19 18:06:36
Message-ID: 20071119180636.GF19288@decibel.org (view raw or flat)
Thread:
Lists: pgsql-novice
Please reply-all so everyone can participate. And top-posting == bad ;)

On Mon, Nov 19, 2007 at 09:39:18AM -0800, G. J. Walsh wrote:
> Thanks for the comment.
> 
> I am currently using 8.2 - 8.3 is not yet available on Mandriva Cooker. 
> 
> All I am needing to do is manage a fixed character length which would
> hold a prechecked response for a stated number of items. Since then I
> have experimented with throwing that 'string' back and forth, managing
> it with PHP which would be necessary in any case, the responses
> originating within a form. In effect, I am now managing a character type
> of given length rather than an array. The '?' was simply a marked filler
> indicating a lack of response for that item. The only overhead I see is
> the need to 'fill' the array when a record (row) is initiated and that
> is pretty straightforward.
> 
> Your suggestion is to set up an array 'any' filled with nulls. If that
> is what you suggest I do with 3.5, it might be worth it to download
> source for PostgreSQL and give it a try before I 'freeze' the table
> design and get into production. However, it seems to me that there is
> little to be gained in overall effectiveness between the two approaches
> in this particular application.
> 
> By all means correct me if I am wrong about this. 

Technically, an array with NULL values for unanswered questions would be
more correct... but if every answer is a single character, that doesn't
really buy you a lot over just using a string. It might actually have a
much larger overhead, too... I suspect that every element in the array
will have a varlena header, which would cost you an extra 1-4 bytes.

> On Sun, 2007-11-18 at 22:31 -0600, Decibel! wrote:
> > On Nov 14, 2007, at 8:30 PM, Kenneth Porter wrote:
> > > On Wednesday, November 14, 2007 12:09 PM -0800 "G. J. Walsh"  
> > > <gjwalsh(at)dscdirectionalservices(dot)com> wrote:
> > >
> 
> > >> In defining this, I plan on something like: ans CHAR(1) ARRAY[192]
> > >>
> > >> But I learned that PostgreSQL does not 'enforce' this. I would rather
> > >> have an '?' placed in each of the 192 array elements (and thereby
> > >> constrain with NOT NULL) to indicate lack of a response (the default)
> > >> when the test records are first established for the client.
> > >
> 
> > IIRC, in 8.3 elements within an array can be NULL, would would be  
> > what you're looking for. ('?' is just a not-so-good way of  
> > representing "I don't know", which is why NULL is for. :) )
> 

-- 
Decibel!, aka Jim C. Nasby, Database Architect  decibel(at)decibel(dot)org 
Give your computer some brain candy! www.distributed.net Team #1828

In response to

pgsql-novice by date

Next:From: Alex du PlessisDate: 2007-11-19 20:46:28
Subject: Database version control
Previous:From: Sean DavisDate: 2007-11-19 15:03:41
Subject: xpath question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group