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

标签 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

最佳答案

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

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

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

相关文章:

postgresql - PL/pgSQL "for loop"+ 选择基本示例 ("hello world")

ruby-on-rails - ActiveRecord::Base.connection.execute 与 Postgres 受影响的行

django - PostgreSQL 数据库服务器无响应

sql - 从连接表中获取多个不同的值

java - 将 xml 模式导入 postgres 以自动创建一个表,然后用 xml 文件填充它?

sql - 使用默认值重载 Postgres 函数 - 我的函数是不可调用的吗?

java - "java.lang.NoSuchFieldError: NONE"与 Spring 3、maven、JPA、c3p0 hibernate

database-design - 数据库设计 : best practices to hierarchical structure

PostgreSQL 角色继承不起作用?

sql - Postgres 不允许 localhost 但可以使用 127.0.0.1