3

I have a materialized view with an unknown column name, and I need to give that column a name. I can't just recreate the view because it took a long time to create.

dba=# \d temp_name_relationships;                                                    
Materialized view "temp_name_relationships"
  Column  |       Type       | Modifiers
----------+------------------+-----------
 id       | bigint           |
 source   | integer          |
 name1    | text             |
 name2    | text             |
 ?column? | double precision |
 sum      | bigint           |

That ?column? in there is the offender. How do I rename it? I've tried:

ALTER MATERIALIZED VIEW temp_name_relationships RENAME COLUMN ?column? TO score;
ERROR:  syntax error at or near "?"

1 Answer 1

2

I just remembered you can quote table names, and I guess this works to escape the question marks.

ALTER MATERIALIZED VIEW temp_name_relationships RENAME COLUMN "?column?" TO score;
2
  • 2
    No need to guess. Do it and you'll see it works. Commented Jun 22, 2016 at 2:05
  • 1
    can you mark as chosen? Commented Sep 26, 2017 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.