Re: COPY to table with array columns (Longish)

From: "Phillip Smith" <phillips(at)weatherbeeta(dot)com(dot)au>
To:
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: COPY to table with array columns (Longish)
Date: 2006-06-13 23:22:30
Message-ID: 003201c68f40$3e392850$9b0014ac@ITPhil
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks Aaron - There are currently 8175 records in my SYS file - I might
need to go with this approach but be selective about which items I export so
I don't end up with 8000 tables related to SYS! There's probably a lot of
**** in there that doesn't actually need to be exported.

Thanks again,
-p

-----Original Message-----
From: pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org]
On Behalf Of Aaron Bono
Sent: Wednesday, 14 June 2006 1:05 AM
To: phillips(at)weatherbeeta(dot)com(dot)au
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] COPY to table with array columns (Longish)

So how about creating a sys table too:

SYS
sys_id

ZKCOST
sys_id,
zkcost_id,
zkcost_value

and

ZPRECMPL
sys_id,
zprecmpl_id,
zprecmpl_value

This gives you the flexibility to expand to as many "columns" for
ZPRECMPL as you want. The bottom line is, I think it would be much
more efficient storage to determine a way to turn your variable number
of columns into rows of a value table.

For example, I have a web site for role playing games. Since each
game has different attributes for the characters you play, I need a
flexible way to define the list of attributes and then allow people to
enter the values of those attributes. Below is a simplified version
of my table structure:

attribute
attribute_id (PK),
attribute_name

character
character_id (PK),
character_name

character_attribute
character_attribute_id (PK),
character_id (FK),
attribute_id (FK),
value

It is a little different than your problem but demonstrates how a
variable number of columns (in this case a variable number of
attributes for a character) can be stored with one row representing
each column.

Because I don't understand the context of your problem as well as you
do, you will probably have to determine how to tweak this to meet your
needs. But I think, from the information you have provided, that this
"pivoted" table approach will work for you.

-Aaron

On 6/13/06, Phillip Smith <phillips(at)weatherbeeta(dot)com(dot)au> wrote:
> Not quite... ZKCOST and ZPRECMPL are two completely different things. They
> have no relation except they're both stored in the SYS table in D3.
>
> If we put it in a tree:
> SYS
> |
> +- ZKCOST
> | \- <value>
> |
> +- ZPRECMPL
> | +- <value>
> | +- <value>
> | +- <value>
> | \- <value>
>
> or table:
> SYS
> +-----------+---------+---------+---------+---------+
> | ZKCOST | <value> | | | |
> | ZPRECMPL | <value> | <value> | <value> | <value> |
> +-----------+---------+---------+---------+---------+

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee. If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2006-06-14 00:41:18 Re: COPY to table with array columns (Longish)
Previous Message Rommel the iCeMAn 2006-06-13 23:19:33 Error with "limit" clause