json - Preserve column names when converting the results of a query to hstore -


i have table users columns user_id, user_name , user_phone example.

if do:

select hstore(u) users u 

the result is:

"user_id" => "1", "user_name" => "mcenroe", "user_phone" => "xxx" 

if do:

select hstore(u) (select user_id, user_name, user_phone users) u 

the result is:

"f1" => "1", "f2" => "mcenroe", "f3" => "xxx" 

i lose name of columns.
how can use 2nd example , having correct column name?

this shortcoming fixed postgres 9.2.
quote release notes 9.2 here:

e.5.3.3. queries

(...)

  • retain column names @ run time row expressions (andrew dunstan, tom lane)

    this change allows better results when row value converted hstore or json type: fields of resulting value have expected names.

also, don't use user table name, if it's demo. reserved word in every sql standard , in postgres , cannot used table name without double-quoting. took liberty fix test case in q.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -