John T Cox
John T Cox

Reputation: 101

Postgres is adding a space at the beginning and end of all fields

SLES 12 SP3
Postgres 10.8

I have duplicated a table to migrate data from a DB2 instance. The fields are all of type CHAR, VARCHAR, or TIMESTAMP. I originally tried to use \COPY to pull the data in from a pipe delimited file. But, it put a space at the beginning and end of all of the fields, even if this caused the field to be longer than it is defined. I found a claim online that this was a known issue with \COPY. At that point, I dropped the table, used sed and some other tools to convert the pipe delimited data into an SQL INSERT statement. I again had a leading and trailing space in every field.

There are a lot of columns but as an example of what I have follows:

FLD1  CHAR(6) PRIMARY KEY
FLD2  VARCHAR(8)
FLD3  TIMESTAMP

I am using the short form of INSERT.

INSERT INTO my_table VALUES
('123456', '12345678', '2021-01-01 12:34:56');

But when I do a SELECT, I get (note the leading and trailing spaces):

 123456 | 12345678 | 2021-01-01 12:34:56 |

I would point out that the first two fields are now longer than they are defined by 2 characters.

Does anyone how I might fix this?

Upvotes: 0

Views: 1849

Answers (1)

John T Cox
John T Cox

Reputation: 101

The -A argument to psql gives me the desired result.

Upvotes: 6

Related Questions