How to select with the length of the field / untrim using select
I have this table that I would like to select values from. The thing is that I would like to get the exact amount of length in the output of my select as I have in my table. For example:
CREATE TABLE 开发者_Go百科myschema.test_table
(
id serial NOT NULL,
otyp CHARACTER VARYING(3),
fname CHARACTER VARYING(8),
age integer
) WITH(OIDS=FALSE);
And let's say that this table contain
id | otyp | fname | age
----+------+--------+-----
1 | aa | gustav | 20
(1 row)
SELECT id || otyp || fname || age FROM myschema.test_table;
This would give me this result: 1aagustav20I want the output to be
1aa gustav 20
Any help would appreciated!
Just do
SELECT id || otyp || ' ' || fname || ' ' || age FROM myschema.test_table;
I solved the problem!
SELECT id
|| RPAD(otyp, 3, ' ')
|| RPAD(fname, 8, ' ')
|| age
FROM
myschema.test_table;
精彩评论