I have some tables created under a schema. At the moment, I can access the table within the schema using:
select * from myschema.mytable
I am searching for ways to avoid using the schema name. something like:
select * from mytable
But I'm not finding the answers.
Can you help? Thanks
You can access tables inside schemas in two ways: by referencing them using schema. table notation. by adding the schema to your search_path.
The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable . Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database they are connected to, if they have privileges to do so.
In order to connect to a database you need to know the name of your target database, the host name and port number of the server, and what user name you want to connect as. psql can be told about those parameters via command line options, namely -d, -h, -p, and -U respectively.
Schema search path would work for this:
To see the current value:
SHOW search_path;
To change the value (append new schema):
SET search_path TO myschema,public;
It is documented here, in section 5.7.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With