Sunday 15 January 2012

sql - How can I expand a PostgreSQL row into multiple rows for updating "custom fields"? -


I have a table that is used by a piece of a third party software (user_fields), in each row User_id, a field_id and a field_value that I know is messy.

I also have another user table of mine and user, except field_id it excludes "virtual" and matches custom field mapping.

How can I write a selected query that will turn it off:

  user_id | Company_name | First_name | Country ------------------------------------------------- - 1 | Naughty Choke Company | C. GB2 Lublinz's R Our | Pie | IT  

In this?

  user_id | Field_value | Field_id --------------------------------------- 1 | Naughty Choke Company | 10 1 C. 11 1 | GB 12 2 Lublinz's R Our | 10 2 Pie. 11 2 IT | 12  

I am using Postgresql 8.4, and I intend to query for the query to include.

Extend me to the fields rows, using unnecessary and using an array, but any other field in the selection has been unnosted after processing, and hence the value of unnecessary rows Duplicate.

Any thoughts?

Cheers, C

Edit: Formatting and explanation, which is a nasty name-value table third party.

I'm adding this as a different answer because it is different from the other that I posted is. You can try doing something like this:

  SELECT U.id, UF.id F Field_ID, Case UFDID when 10 UFirst_Name When 11UU CuTi 12V UNPPGN Name If you have user_field table (or whatever name can be given), then it is assumed that you get all the user's fields. Possible. You have to keep your case statement up to date. 


No comments:

Post a Comment