我正在尝试遵循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
答案 0 :(得分:1)
您总是用模式名称hstore
限制public
的事实使我认为该模式不在您的search_path
上。
尝试使用OPERATOR(public.->)
代替->
,看看是否有区别。