0

I created the table:

jyotish=# CREATE TABLE graha(name varchar(80),english_name varchar(80),symbol char(1));

And I try to create a record with the UTF-8 Sun Symbol like this:

jyotish=# INSERT INTO graha VALUES('surya','sun','u\2609');

I get the error:

ERROR:  value too long for type character(1)

How do I put UTF-8 symbols in a column?

Nicholas Booth
  • 49
  • 1
  • 10
  • 2
    Your unicode escape syntax is invalid. In fact, there is no language, which works that way (some may accept `'\uXXXX'` as a unicode escape, but not `'u\XXXX'`). Postgresql uses the [standard-compatible syntax](http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-UESCAPE): `U&'\XXXX'` [by default](http://www.postgresql.org/docs/current/static/runtime-config-compatible.html#GUC-STANDARD-CONFORMING-STRINGS). – pozs Mar 09 '15 at 12:43

1 Answers1

0

I get the error:

ERROR: value too long for type character(1)

If your problem is above then,

You have assigned the length of character in column symbol to 1(symbol char(1)), so you can only insert values with length of 1

in your insert statement you've trying to insert 'u\2609'(length=6) to column symbol it's not possible

solution : ALTER TABLE graha ALTER COLUMN symbol TYPE character varying(100);


How do I put UTF-8 symbols in a column?

Create Database with UTF-8 encoding

CREATE DATABASE mydb    ENCODING = 'UTF8'

or you want to alter the existing database then see this answer

Community
  • 1
  • 1
Vivek S.
  • 19,945
  • 7
  • 68
  • 85