如何从 postgresql 中获取 TEXT 列值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12155648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:14:21  来源:igfitidea点击:

How to fetch TEXT column value from postgresql

postgresql

提问by Ben Bracha

I have a the following simple table in postgreSQL:

我在 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:

正如我在 phpPgAdmin 网站上看到的那样, text_column 的值是数字(长)。在我阅读时,postgreSQL 保留了一个指向实际数据的指针。如何获取 text_column 的实际字符串值?正在做:

select text_column from data 

returns numbers...

返回数字...

Thanks

谢谢

回答by asm0dey

Following helped us:

以下帮助我们:

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

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

其中value是字段,其中包含TEXT,而 t_field 显然是表的名称。

回答by Najitaka

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.

从 psql 运行 \lo_export ID FILE,其中 ID 是存储在表中文本列中的数字,FILE 是结果的路径和文件名。该数字是对大对象表的引用。您可以通过运行 \lo_list 查看其内容。

回答by gks

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