Question

I have a table, which has a column "description" of type TEXT. If I do:

SELECT id, description FROM table_name;

I see in "description" column instead of text value a number. Is there any way to see the text value?

Edit: After some testing I found out why I see numbers, but others like Craig see real text. It's because the data are inserted using Hibernate.

Entity:

@Entity public class Settings {

@Id
@GeneratedValue
private Integer id;

@Column(nullable = false, unique = true)
private String key;

@Lob
@Column(nullable = false, length = Integer.MAX_VALUE)
private String value;

// getters and setters

}

Log result:

Hibernate: create table Settings (id int4 not null, key varchar(255) not null, value text not null, primary key (id));

Hibernate: select nextval ('hibernate_sequence') Hibernate: insert into Settings (key, value, id) values (?, ?, ?) 16:05:32,718 TRACE BasicBinder:81 - binding parameter [1] as [VARCHAR] - [GoogleSiteVerification] 16:05:32,718 TRACE BasicBinder:81 - binding parameter [2] as [CLOB] - [] 16:05:32,726 TRACE BasicBinder:81 - binding parameter [3] as [INTEGER] - [4]

If I do in pgAdmin3 this select:

select * from settings;

I see this result:

1;"GoogleSiteVerification";"112351"

Was it helpful?

Solution

Added @Type(type = "org.hibernate.type.TextType") to attribute annotated with @Lob. Now it works as desired.

Also it solved the issue with encoding, which was the reason I opened pgAdmin in the first place (to see what's inside).

Technical detail: PostgreSQL stored LOB in separate place and referenced it by a numerical identifier (which was what the number which confused me).

OTHER TIPS

Setup:

CREATE TABLE table_name (id integer, description text);

INSERT INTO table_name(id, description) values (1, '12');

Demo:

testdb=> SELECT id, description FROM table_name;
 id | description 
----+-------------
  1 | 12
(1 row)

Yup, I'd say you have a number in your description column because there's a number in your description column.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top