pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: James Taylor <jtx@hatesville.com>
To: pgsql-sql@postgresql.org
Subject: Rows as Columns
Date: Tue, 1 Apr 2003 16:17:39 -0800
Message-ID: <002801c2f8ad$4888c9f0$4500a8c0@theplague> (raw)

Hi everyone, I just joined this list a few days ago...

Now, I have a question, and I'm not even sure if this is possible
without having to make numerous statements.

Say I have two tables with the following columns and this data:

types:
id   | name
-----------------
1    | first_name
2    | last_name
3    | phone_number

data:
id   | data     | t_key | cust_id
---------------------------------
1    | Sam      | 1     | 1
2    | Smith    | 2     | 1
3    | 555-1212 | 3     | 1
4    | John     | 1     | 2


Types basically describes what the column type is.  t_key references the
type, cust_id is the user id.

i'd want to do something like "select t.name, d.data from types t, data
d where d.cust_id = 1"

This would return something like:

name         | data
------------------------
first_name   | Sam
last_name    | Smith
phone_number | 555-1212


Well, I need it to somehow return that data in this format:

first_name   | last_name  | phone_number
----------------------------------------
Sam          | Smith      | 555-1212



The information in Types is not static, so I can't declare the col names
based on what you see here.

Any suggestions on this one?




view thread (3+ messages)  latest in thread

Message-ID: <002801c2f8ad$4888c9f0$4500a8c0@theplague>
Permalink:  ../002801c2f8ad$4888c9f0$4500a8c0@theplague/
Also on:    postgresql.org/message-id/002801c2f8ad$4888c9f0$4500a8c0@theplague

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jtx@hatesville.com
  Subject: Re: Rows as Columns
  In-Reply-To: <002801c2f8ad$4888c9f0$4500a8c0@theplague>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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