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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: populating arrays with default values



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:

I come from a long background with C and isam. Moving into php and
postgresql is therefore not all that strange, but I suffer with the
comparative lack of structure at times.

Same here. I'm a power C++ guy but relatively new at SQL. I can read it but not yet write it fluently.

My advice: remember that SQL is a set definition language. Always think in terms of sets/groups of data, and not in terms of a series of operations you need to perform.

I deal with a lot of psych scoring and am establishing tables which will contain the response patterns for each individual test within a battery.
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.

Instead of a char, could you use an enumeration? Are there in fact 256 distinct answers for each array position? (I'm not certain that SQL, or the PostgreSQL dialect, have such a thing.)

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


Attachment: smime.p7s
Description: S/MIME cryptographic signature



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group