3

I'm using postgres database and it has table with name say 'System Tenant'. Now I want to make query on it, I do -

select * from "System Tenant";

but it results into error -

ERROR:  relation "System Tenant" does not exist
LINE 1: select * from "System Tenant"
                       ^

Could you please suggest how I can resolve it?

4
  • Try using escape sequence : select * from "System\ Tenant" Commented May 16, 2018 at 12:08
  • This still did not work. Commented May 16, 2018 at 12:29
  • What name exactly does \d show you in psql (or select tablename from pg_tables where lower(tablename) like 'system%')? I guess it might be "system tenant" or "SYSTEM TENANT" or something similar - as soon as you use double quotes the name is case sensitive. Commented May 16, 2018 at 12:35
  • @user5542464: the backslash is not an "escape character" in SQL strings Commented May 16, 2018 at 12:37

1 Answer 1

3

lets say:

so=# create schema t;
CREATE SCHEMA
so=# create table t."Bad Name"();
CREATE TABLE
so=# create table "b@d Name"();
CREATE TABLE

now find all:

so=# select oid::regclass from pg_class where relname ilike '% name%';
     oid
--------------
 t."Bad Name"
 "b@d Name"
(2 rows)

and use exactly as it is listed:

so=# select * from t."Bad Name";
--
(0 rows)

or

so=# select * from "b@d Name";
--
(0 rows)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.