gpt4 book ai didi

sql - 如何解决 PostgreSQL 中缺少 FROM 子句的问题?

转载 作者:行者123 更新时间:2023-11-29 12:51:49 33 4
gpt4 key购买 nike

我在 PosgreSQL 中创建了以下表和类型。

CREATE TYPE WordTy AS (
id VARCHAR(20)
);

CREATE TYPE PageTy AS (
url VARCHAR(100),
title VARCHAR(60),
data_lettura DATE
);

CREATE TYPE OccurrenceTy AS (
word WordTy,
page PageTy,
occurrences_number INTEGER
);

CREATE TABLE Page OF PageTy(PRIMARY KEY(url));

CREATE TABLE Word OF WordTy(PRIMARY KEY(id));

CREATE TABLE Occurrence OF OccurenceTY;

我想知道包含给定单词的所有页面。
当我运行此查询时:

SELECT occ.page.title as page_title, occ.page.url as url_page FROM 
Occurrence occ WHERE occ.id=1

输出是:

ERROR:  missing FROM-clause entry for table "page"

我哪里错了?

最佳答案

参见 Accessing Composite Types .

您需要使用括号:(occ.page).title


您的 SQL 中也有一些拼写错误:

CREATE TABLE Occurrence OF OccurenceTY;

应该是

CREATE TABLE Occurrence OF OccurrenceTy;

FROM Occurrences occ

应该是

FROM Occurrence occ

WHERE occ.id=1

应该是

WHERE (occ.word).id='1'


最终查询:

SELECT (occ.page).title as page_title, (occ.page).url as url_page FROM 
Occurrence occ WHERE (occ.word).id='1'

关于sql - 如何解决 PostgreSQL 中缺少 FROM 子句的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52235122/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com