How to do this ?

From: Adarsh Sharma <adarsh(dot)sharma(at)orkash(dot)com>
To: Christian Ullrich <chris(at)chrullrich(dot)net>, Chetan Suttraway <chetan(dot)suttraway(at)enterprisedb(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: How to do this ?
Date: 2011-05-18 11:25:48
Message-ID: 4DD3ACBC.9020000@orkash.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dear all,

I explain in the simple terms :

Our application stores data in a format that is not best fitted
to analyze.

_*Table news

*_category_id Record_id field_name field_value

78 21 Village
adasrpur
78 21 SOI
media
78 21 Heading CM dies
78 21 Description In the
agdadjkagdasgdjkhasdkajhgdhjsajhdgasdhgaksgda .....

80 22 SOI
media
80 22 Units
in the armed forces
80 22 EventLoc
kashmir
80 22 GR
encounter
80 22 Other Perspective ""
80 22 Heading
A bomb takes 100 lives

78 23 Village
chattarpur
78 23 SOI
media
78 23 Heading PM
address nation
78 23 Description on the
eve of Republic day Pm addresses nation and ensures safety
asjhdgakhgdjla....

80 22 SOI
media
80 22 Units
military academy
80 22 EventLoc
Hyderabad
80 22 GR
firing
80 22 Other Perspective ""
80 22 Heading
militantas have a firing near military academy

_*category_table :

*_category_id category_name
78 Political
80 Criminal
..........
.........
....

Problem :-

1. There are more than 40000 rows and different *category_id* have
different number of rows ( field_name,fild_values)
2. There may be case when different *category_id's* have different
*field_name.
3. *In future there may be 1000 of categories and millions of news.
*
Requirement :

* We want the desired data in horizontal format and field_name becomes
the table columns for e.g ;

A user inputs category = Criminal then output will be :

*category_id category_name SOI Units
EventLoc GR Other
Perspective Heading*
80 Criminal media in
the armed forces Kashmir encounter ""
A bomb takes 100 lives
80 Criminal media
military academy Hyderabad firing ""
militantas have a firing near military
academy

||rly catgory_id 78 has also its rows.

Note that on other category_id column names may change.

My procedure :
1. create a temporary table depending upon *field_name* column of the
corresponding id.
2. Load data in it from user_news table.
3. Select data from the temporary table.

I am not able to load data.
Please guide what is the correct way to achieve this.

I attach my procedure. Please let me know if any other information is
required.

I can do it myself if someone show me the path to do this

Thanks & best Regards
Adarsh Sharma

Attachment Content-Type Size
user_news.txt text/plain 555 bytes

Responses

Browse pgsql-general by date

  From Date Subject
Next Message G. P. 2011-05-18 11:31:43 Re: re-install postgres/postGIS without Loosing data??
Previous Message Szymon Guz 2011-05-18 11:21:18 question about readonly instances