How to do this ? - Mailing list pgsql-general
From | Adarsh Sharma |
---|---|
Subject | How to do this ? |
Date | |
Msg-id | 4DD3ACBC.9020000@orkash.com Whole thread Raw |
Responses |
Re: How to do this ?
|
List | 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
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
pgsql-general by date: