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

时间:2018-06-19 11:38:21

标签: postgresql

我正在尝试遵循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

1 个答案:

答案 0 :(得分:1)

您总是用模式名称hstore限制public的事实使我认为该模式不在您的search_path上。

尝试使用OPERATOR(public.->)代替->,看看是否有区别。