Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

On running the below command in bash throws:

ERROR: relation "testschema.testtable" does not exist.

Command line:

psql -h "localhost" -d "postgres" -U "postgres" -c "select * from TestSchema.TestTable;"

Why is it searching relation rather than schema? How can I set default schema to be searched, and can I set a list of multiple schemas from multiple databases as default list?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Why is it searching relation rather than schema?

TestSchema.TestTable is a relation (table). I is a fully qualified table name.

The reason it's not finding it, is most probably because you created the schema and the table using doublequotes:

create table "TestSchema"."TestTable" (...)

which makes the names case sensitive and forces you to always use quotes to qualify the name. Please see the manual for details about "delimited identifiers" (aka "quoted identifiers):

http://www.postgresql.org/docs/9.2/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

How can I set default schema to be searched

See the "set schema" statement: http://www.postgresql.org/docs/current/static/sql-set.html

You can also define a default schema using the ALTER USER command.

can I set a list of multiple schemas from multiple databases as default list

Yes, set the search_path configuration variable: http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-SEARCH-PATH

This can also be set permanently through an ALTER USER statement.

share|improve this answer
    
Thanks, it worked :) –  user2104242 Feb 24 '13 at 11:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.