Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My PostgreSQL auto inserts many space characters after the value of a field

Tags:

postgresql

When I insert data in PostgreSQL, it is auto inserting many spaces after the value of the field.

I tired to fix it, but I can't find anything

For example: I want to insert value 'John' in column 'Name'. It inserts spaces after John.

->> 'John______________________________________________________________'
like image 621
Huy Pics Avatar asked Oct 30 '12 03:10

Huy Pics


People also ask

How do I get rid of white space in PostgreSQL?

The LTRIM() function removes all characters, spaces by default, from the beginning of a string. The RTRIM() function removes all characters, spaces by default, from the end of a string. The BTRIM function is the combination of the LTRIM() and RTRIM() functions.

How do I change the space in PostgreSQL?

In PostgreSQL, the TRIM() function is used to remove the longest string consisting of spaces or any specified character from a string. By default, the TRIM() function removes all spaces (' ') if not specified explicitly.

What is character varying in Postgres?

The notations varchar( n ) and char( n ) are aliases for character varying( n ) and character( n ) , respectively. character without length specifier is equivalent to character(1) . If character varying is used without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension.

What is :: text in PostgreSQL?

PostgreSQL supports a character data type called TEXT. This data type is used to store character of unlimited length. It is represented as text in PostgreSQL. The performance of the varchar (without n) and text are the same. Syntax: variable_name TEXT.


1 Answers

character is an awful data type that should not be used. This is just one of the reasons. See character types - postgresql manual.

Change those fields to text or to varchar(n). text with a check constraint on length where one is required is usually the best option.

ALTER TABLE thetable ALTER COLUMN colname TYPE text;

BTW, it's easier to answer your questions if you post the SQL and - preferably - the output of running that SQL in psql, which produces copy-and-pasteable plain text output.

like image 62
Craig Ringer Avatar answered Dec 04 '22 20:12

Craig Ringer