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______________________________________________________________'
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With