0
我想知道如何在select查詢中引用外鍵表字段(在PostgreSQL 9.3中)。 我有如下表:隱式引用sql查詢中的外鍵表字段
CREATE TABLE "Threads" (
"Id" integer NOT NULL,
"Board" char(30) NOT NULL,
CONSTRAINT "Threads_pkey"
PRIMARY KEY ("Id", "Board"));
CREATE TABLE "Posts" (
"PostId" integer NOT NULL,
"Text" text,
"Thread" integer NOT NULL,
CONSTRAINT "Posts_pkey"
PRIMARY KEY ("PostId"),
CONSTRAINT "Thread"
FOREIGN KEY ("Thread") REFERENCES "Threads"("Id"));
我要輸出以下字段:帖子ID,文字,董事會。此前(不是在PostgreSQL系統)。我寫的是這樣的:
SELECT
"PostId",
"Text",
"Thread"->"Board"
FROM "Posts";
PostgreSQL的人似乎都需要顯式連接:
SELECT
"PostId",
"Text",
"Board"
FROM "Posts"
INNER JOIN "Threads" ON ("Posts"."Thread" = "Threads"."Id")
有什麼辦法來寫這個查詢沒有說明這種明顯加入?我也試過這個變種:
SELECT
"PostId",
"Text",
"Thread"."Board"
FROM "Posts";
但這也引發了一個錯誤。
爲什麼指定加入問題? –
@ muistooshort懶惰。 – rfg