title: Postgress image in Docker change collate for exist column or for db
body: <p>I faced with problem sorting by name with swedish data.
  How to change collate for some exist column or for table in Postgres 9.6 in docker. </p>
  
  <p>when I try change it for table</p>
  
  <p><code>alter table brnad convert to character set utf8 collate utf8_swedish_ci;</code></p>
  
  <p>faced with error</p>
  
  <p><code>&gt; ERROR:  syntax error at or near "convert"</code></p>
  
  <p>when I try to use for column </p>
  
  <pre><code>ALTER TABLE brand ALTER COLUMN name SET DATA TYPE character varying(255) COLLATE 'utf8_swedish_ci'
  </code></pre>
  
  <p>faced with same error </p>
  
  <pre><code>ALTER TABLE brand ALTER COLUMN name SET DATA TYPE character varying(255) COLLATE 'utf8_swedish_ci'
  &gt; ERROR:  syntax error at or near "'utf8_swedish_ci'"
    LINE 1: ...name SET DATA TYPE character varying(255) COLLATE 'utf8_swed...
                                                                 ^
  
  &gt; Time: 0.001s
  </code></pre>
  
  <p>I suggested maybe problem with container and research information about <code>locale-gen</code></p>
  
  <p>docker-compose.yml </p>
  
  <pre><code>postgres:
      image: postgres:9.6
      command: locale-gen sv_SE.utf8
      ports:
          - '5432:5432'
      container_name: 'postgresql'
      working_dir: /app
      restart: always
      environment:
          POSTGRES_DB: ${POSTGRES_DB}
          POSTGRES_USER: ${POSTGRES_USER}
          POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
          LANG: 'sv_SE.UTF-8'
          LANGUAGE: 'sv_SE.UTF-8'
          LC_ALL: 'sv_SE.UTF-8'
          LC_COLLATE: 'sv_SE.UTF-8'
          LC_CTYPE: 'sv_SE.UTF-8'
      volumes:
          - ./data/postgresql:/var/lib/postgresql/data
      networks:
          - php
  </code></pre>
  
  <p>faced with another problem </p>
  
  <pre><code>bash: warning: setlocale: LC_ALL: cannot change locale (sv_SE.UTF-8)
  Generating locales (this might take a while)...
  Generation complete.
  </code></pre>
  
  <p>and image everytime restaring (State Restarting).. </p>
  
  <p>when remove <code>commnad</code> image up without error but when I entered in image I faced with that</p>
  
  <pre><code>root@d09bb8a58b90:/app# locale
  locale: Cannot set LC_CTYPE to default locale: No such file or directory
  locale: Cannot set LC_MESSAGES to default locale: No such file or directory
  locale: Cannot set LC_ALL to default locale: No such file or directory
  LANG=sv_SE.UTF-8
  LANGUAGE=sv_SE.UTF-8
  LC_CTYPE="sv_SE.UTF-8"
  LC_NUMERIC="sv_SE.UTF-8"
  LC_TIME="sv_SE.UTF-8"
  LC_COLLATE="sv_SE.UTF-8"
  LC_MONETARY="sv_SE.UTF-8"
  LC_MESSAGES="sv_SE.UTF-8"
  LC_PAPER="sv_SE.UTF-8"
  LC_NAME="sv_SE.UTF-8"
  LC_ADDRESS="sv_SE.UTF-8"
  LC_TELEPHONE="sv_SE.UTF-8"
  LC_MEASUREMENT="sv_SE.UTF-8"
  LC_IDENTIFICATION="sv_SE.UTF-8"
  LC_ALL=sv_SE.UTF-8
  root@d09bb8a58b90:/app# psql --username=minimoj
  perl: warning: Setting locale failed.
  perl: warning: Please check that your locale settings:
      LANGUAGE = "sv_SE.UTF-8",
      LC_ALL = "sv_SE.UTF-8",
      LC_COLLATE = "sv_SE.UTF-8",
      LC_CTYPE = "sv_SE.UTF-8",
      LANG = "sv_SE.UTF-8"
      are supported and installed on your system.
  perl: warning: Falling back to the standard locale ("C").
  /bin/bash: warning: setlocale: LC_ALL: cannot change locale (sv_SE.UTF-8)
  psql (9.6.17)
  Type "help" for help.
  </code></pre>
  
  <p>how to change collate for exist column ? how to change collate for exist table ? How to convert exist data to new collate, because data was saved with en_US.UTF-8 ? </p>