如何显示大对象 (LOB) 内容?

483*_*347 4 postgresql psql blob

我如何才能查看 LOB 内容?

\d ticketgrantingticket

              Table "public.ticketgrantingticket"
          Column           |          Type          | Modifiers 
---------------------------+------------------------+-----------
id                         | character varying(765) | not null
number_of_times_used       | numeric(10,0)          | 
creation_time              | numeric(19,0)          | 
last_time_used             | numeric(19,0)          | 
previous_last_time_used    | numeric(19,0)          | 
ticketgrantingticket_id    | character varying(765) | 
expiration_policy          | oid                    | 
authentication             | oid                    | 
services_granted_access_to | oid                    | 
expired                    | boolean                | 
proxied_by                 | character varying(1)   | 
Indexes:
    "ticketgrantingticket_pkey" PRIMARY KEY, btree (id)

SELECT expiration_policy, 
       authentication, 
       services_granted_access_to 
FROM ticketgrantingticket LIMIT 2;

 expiration_policy | authentication | services_granted_access_to 
-------------------+----------------+----------------------------
           1165742 |        1165743 |                    1165744
           1165757 |        1165758 |                    1165759
(2 rows)
Run Code Online (Sandbox Code Playgroud)

这默认显示这些数字。

到目前为止,我发现在我的客户中以某种方式无法正常工作:

SELECT expiration_policy, 
       encode(authentication::bytea, 'escape'),
       services_granted_access_to 
FROM ticketgrantingticket LIMIT 2;

ERROR:  cannot cast type oid to bytea
LINE 1: SELECT expiration_policy, encode(authentication::bytea, 'esc...
Run Code Online (Sandbox Code Playgroud)

我可以在 pgAdmin III 中看到相同的内容。

我期待那里有 blob,因为 IINMoid可以用作大对象引用。我们正在使用,oid因为不知道我们在做什么。到目前为止,我已经评估这三列中的一列将安全且有利可图地转换为bytea,但是我无法在源(非 postgres)系统中窥探其他两列的内容,所以我决定在这个(postgres)系统中窥探它们) 目标系统。

483*_*347 6

我跑了

SELECT expiration_policy, lo_get(authentication), services_granted_access_to 
FROM ticketgrantingticket
LIMIT 2;
Run Code Online (Sandbox Code Playgroud)

阅读https://www.postgresql.org/docs/current/static/lo-funcs.html后,由现已失效的评论建议。那奏效了。

  • 在 PostgreSQL 10 中,这需要是例如`lo_get(authentication::oid)` (4认同)

Eva*_*oll 5

因为这个问题即将结束,我将粘贴 Andriy M 提供的链接和其他一些链接。

大型物体有点深奥。它们允许你探索它们的内部。通常您会在它们之上构建系统,例如 PostGIS 中的栅格支持。附带说明一下,psql有一些助手。

\dl                    list large objects, same as \lo_list
\lo_export LOBOID FILE
\lo_import FILE [COMMENT]
\lo_list
\lo_unlink LOBOID      large object operations
Run Code Online (Sandbox Code Playgroud)

这些几乎都是可用作客户端函数的函数。