Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres query fails without schema

Tags:

postgresql

THis doesn't work, resulting in ERROR: relation "user" does not exist

select * from "user"

This one does

select * from "dbo"."user"
like image 916
Tuan Anh Tran Avatar asked Jul 27 '26 13:07

Tuan Anh Tran


1 Answers

Tables that aren't schema-qualified are searched for on the search_path. This doesn't search every schema. By default it only searches:

  • pg_catalog (implicitly always first, not listed on search_path)
  • pg_temp tablespaces (implicit, not listed on search_path)
  • A schema named after the current user, listed as $user in search_path
  • The public schema

If you want PostgreSQL to look elsewhere you have to modify the search_path to tell it so, or fully schema-qualify the name.

See the PostgreSQL manual on search_path.

Also, note that unlike some databases the name dbo has no particular significance in PostgreSQL. It's just another name.

like image 186
Craig Ringer Avatar answered Jul 30 '26 02:07

Craig Ringer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!