gpt4 book ai didi

postgresql - 在 hstore 列上选择不起作用 (PostgreSQL)

转载 作者:行者123 更新时间:2023-11-29 12:08:06 25 4
gpt4 key购买 nike

我正在尝试关注 this tutorial了解 hstore 功能。

我启用了扩展,可以毫无问题地插入数据。

但是,一旦我尝试像这样从 hstore 列中选择数据:

SELECT attr -> 'ISBN-13' AS isbn
FROM books;

我收到以下错误:

ERROR:  operator does not exist: public.hstore -> unknown LINE 23:  attr -> 'ISBN-13' AS isbn
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

我确信扩展已正确启用,否则我什至无法创建包含 hstore 列的表。

创建表、插入数据并选择它的完整代码:

--DROP TABLE books;   
CREATE EXTENSION IF NOT EXISTS hstore;

CREATE TABLE books (
id serial primary key,
title VARCHAR (255),
attr public.hstore
);


INSERT INTO books (title, attr)
VALUES
(
'PostgreSQL Tutorial',
'"paperback" => "243",
"publisher" => "postgresqltutorial.com",
"language" => "English",
"ISBN-13" => "978-1449370000",
"weight" => "11.2 ounces"'
);

-- Error occurs here
SELECT
attr -> 'ISBN-13' AS isbn
FROM
books;
--

版本:

PostgreSQL 10.4 on x86_64-pc-mingw64, compiled by gcc.exe (Rev5, Built by MSYS2 project) 4.9.2, 64-bit

最佳答案

您总是使用架构名称 public 限定 hstore 这一事实让我认为该架构不在您的 search_path 上。

尝试使用 OPERATOR(public.->) 而不是 -> 看看是否有区别。

关于postgresql - 在 hstore 列上选择不起作用 (PostgreSQL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50927496/

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