pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: danycxxx <danycxxx@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Select row cells as new columns
Date: Fri, 25 May 2012 02:03:41 -0700 (PDT)
Message-ID: <1337936621862-5709987.post@n5.nabble.com> (raw)

Hello. I hope you can help me with this or at least guide me into the right
direction:

I have 2 tables:

CREATE TABLE infos
(
  id integer NOT NULL DEFAULT nextval('info_id_seq'::regclass),
  name text NOT NULL,
  id_member integer NOT NULL,
  title text,
  min_length integer NOT NULL DEFAULT 0,
  max_length integer NOT NULL DEFAULT 30,
  required boolean NOT NULL DEFAULT false,
  type text NOT NULL DEFAULT 'text'::text,
  CONSTRAINT info_pkey PRIMARY KEY (id ),
  CONSTRAINT infos_id_member_fkey FOREIGN KEY (id_member)
      REFERENCES members (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
  OIDS=FALSE
);
ALTER TABLE infos
  OWNER TO postgres;

-- Index: info_id_idx

-- DROP INDEX info_id_idx;

CREATE INDEX info_id_idx
  ON infos
  USING btree
  (id );

and 

CREATE TABLE info_data
(
  id serial NOT NULL,
  id_info integer,
  value text,
  CONSTRAINT info_data_pkey PRIMARY KEY (id ),
  CONSTRAINT info_data_id_info_fkey FOREIGN KEY (id_info)
      REFERENCES infos (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
  OIDS=FALSE
);
ALTER TABLE info_data
  OWNER TO postgres;

-- Index: info_data_id_idx

-- DROP INDEX info_data_id_idx;

CREATE INDEX info_data_id_idx
  ON info_data
  USING btree
  (id );

with the following values:

infos: 
COPY infos (id, name, id_member, title, min_length, max_length, required,
type) FROM stdin;
1	nume	1	Nume	0	30	t	text
2	prenume	1	Prenume	0	30	t	text
3	cnp	1	C.N.P.	13	13	t	number
4	nume anterior	1	Nume anterior	0	30	f	text
5	stare civila	1	Starea civila	0	30	f	text
6	cetatenie	1	Cetatenie	0	30	f	text
7	rezidenta	1	Rezidenta	0	30	f	text
9	tip act	1	C.I. / B.I.	0	10	t	text
10	serie ci	1	Serie C.I. / B.I.	0	30	t	text
11	numar ci	1	Numar C.I. / B.I.	0	30	t	text
12	data eliberarii	1	Data eliberarii	0	30	t	text
13	eliberat de	1	Eliberat de	0	30	t	text
8	adresa	1	Adresa	0	50	f	text
\.

info_data:
COPY info_data (id, id_info, value) FROM stdin;
1	1	a
2	2	a
3	3	100
4	4	
5	5	
6	6	
7	7	
8	8	
9	9	ci
10	10	sv
11	11	13
12	12	132
13	13	123
14	1	b
15	2	b
16	3	100
17	4	
18	5	
19	6	
20	7	
21	8	
22	9	BI
23	10	XT
24	11	123
25	12	10
26	13	10
\. 

The question:
How can I achive this output?

nume, prenume, cnp, nume anterior, stare civila, ... (as columns - built
from unique rows from infos)
a      , a, .......
b      , b, ....... (as rows)


http://postgresql.1045698.n5.nabble.com/file/n5709987/info_data.sql
info_data.sql 
http://postgresql.1045698.n5.nabble.com/file/n5709987/infos.sql infos.sql 


--
View this message in context: http://postgresql.1045698.n5.nabble.com/Select-row-cells-as-new-columns-tp5709987.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.



view thread (4+ messages)  latest in thread

Message-ID: <1337936621862-5709987.post@n5.nabble.com>
Permalink:  ../1337936621862-5709987.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1337936621862-5709987.post@n5.nabble.com

 · 

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: danycxxx@yahoo.com
  Subject: Re: Select row cells as new columns
  In-Reply-To: <1337936621862-5709987.post@n5.nabble.com>

* 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