> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/appendixes/contrib/dblink/contrib-dblink-get-pkey.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# dblink\_get\_pkey

### dblink\_get\_pkey

dblink\_get\_pkey — 傳回關聯主鍵欄位的位置及欄位名稱

### 語法

```

dblink_get_pkey(text relname) returns setof dblink_pkey_results
```

### 說明

`dblink_get_pkey` 提供本端資料庫中關聯主鍵的資訊。這有時可用於產生要傳送至 遠端資料庫的查詢。

### 引數

*`relname`* : 本端關聯的名稱，例如 `foo` 或 `myschema.mytab`。名稱混合大小寫或含有 特殊字元時，請加上雙引號，例如 `"FooBar"`；未加引號時，字串會折疊為 小寫。

### 傳回值

主鍵的每個欄位傳回一筆資料列；若關聯沒有主鍵，則不傳回資料列。結果的資料列型別定義為：

```

CREATE TYPE dblink_pkey_results AS (position int, colname text);
```

`position` 欄位依序從 1 到 *`N`*；它是該欄位在主鍵中的序號，而非在資料表 欄位中的序號。

### 範例

```

CREATE TABLE foobar (
    f1 int,
    f2 int,
    f3 int,
    PRIMARY KEY (f1, f2, f3)
);
CREATE TABLE

SELECT * FROM dblink_get_pkey('foobar');
 position | colname
----------+---------
        1 | f1
        2 | f2
        3 | f3
(3 rows)
```

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/contrib-dblink-get-pkey.html)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/appendixes/contrib/dblink/contrib-dblink-get-pkey.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
