23

I have a the following simple table in postgreSQL:

CREATE TABLE data ( id bigint NOT NULL, text_column text, );

The values of the text_column , as I see them in the phpPgAdmin web site, are numbers (long). As I read, postgreSQL keeps a pointer to the actual data. How can I fetch the actual string value of the text_column? Doing:

select text_column from data 

returns numbers...

Thanks

2
  • Are you absolutely sure the text_column is defined as text? The behaviour you are describing sounds as if the column is defined as oid - which is the stupid default behaviour of Hibernate when creating LOB columns. Can you copy and paste the output of the \d+ data command in psql? Make sure you do show us the exact output, not some kind of "obfuscated" one. Commented Aug 28, 2012 at 9:05
  • 3
    Checkout this link: stackoverflow.com/q/4488693/330315 and this shredzone.de/cilla/page/299/… and this stackoverflow.com/q/5043992/330315 Commented Aug 28, 2012 at 9:18

4 Answers 4

59

Following helped us:

select convert_from(loread(lo_open(value::int, x'40000'::int), x'40000'::int),  'UTF8') from t_field;

where value is field, which contains TEXT, and t_field is obviously name of table.

Sign up to request clarification or add additional context in comments.

4 Comments

It's probably obvious but the above command does a SELECT ALL essentially. You can also target individual records by using a where clause. E.g. select convert_from(loread(lo_open(value::int, x'40000'::int), x'40000'::int), 'UTF8') from t_field where id=5;
How to delete those records? I can see the text as you describe but If I truncate or drop the table my DB size is not changed. I really want to delete those records
@gunescelil Does VACUUM FULL work for you?
Actually and fortunately we are still not on the production with that code. So I deleted all the postgres table and saved my disk. But later I saw some interfaces of large objects. Maybe someone can use those interfaces to delete the records
4

Provided it's text_column is text, which means it's an oid, this should work too :

select convert_from(lo_get(text_column::oid), 'UTF8') from data;

Comments

3

From psql run \lo_export ID FILE where ID is the number stored in the text column in your table and FILE is the path and filename for the results. The number is a reference to the large object table. You can view its contents by running \lo_list.

Comments

-3

Works fine , May be the field values are in numbers:

 > \d+ type

 Column    | Type    

 name      |  text   

 test_id   | integer   

select name from type;

  name 

   AAA

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.