postgres如何用减号引用表名 [英] postgres how to refer to table names with minus signs

查看:100
本文介绍了postgres如何用减号引用表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否存在引用带有减号的表名的语法。例如,我使用 shp2psql 导入了名为 v-water-a 的表,然后执行了以下操作:

I was wondering if there is a syntax to refer to a table name with minus signs in it. For example, I imported a table called v-water-a using shp2psql, and then did:

select * from v-water-a limit 1;

我收到一个错误:

ERROR:  syntax error at or near "-"
LINE 1: select * from v-water-a limit 1;

如果表名为 v_water_a 。此外,表 v-water-a 在pgadmin3中可见。我试过用单引号将名称引起来,但没有用。

The same query works if the table was named v_water_a. Also, the table v-water-a is visible in pgadmin3. I tried quote the name with single quotes, but it didn't work.

我应该以某种方式对表名加引号吗?

这是Ubuntu 14.04下的PostgreSQL 9.3.5。

Should I quote the table name somehow? or is it the name illegal?
This is with PostgreSQL 9.3.5 under Ubuntu 14.04.

推荐答案

使用双引号:

select * from "v-water-a" limit 1;

文档: http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html

这篇关于postgres如何用减号引用表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆