postgresql - search_path doesn't work as expected with currentSchema in URL -


my sql commands have issues finding objects public schema (which in default db search_path) when specifying currentschema parameter in db connection url.

how fixed?

the long story:

  1. i have application schema app1.
  2. the db has postgis extension installed in public schema (and want keep there).
  3. the db search_path configured this:

    alter database tst set search_path = "$user", public 
  4. when connecting db without specifying current schema in url, default schema public , finds geo functions , objects. have specify app1 schema prefix when addressing objects app1, e.g.:

    select st_asgeojson(geometry,15,4) app1.shapes limit 5 
  5. this not convenient. added "app1" current schema parameter connection url this:

    jdbc:postgresql://localhost:5432/tst?currentschema=app1 
  6. now, when connect db, don't have specify app1 prefix when addressing objects app1 schema. however, requests involve postgis objects don't work anymore , fail with:

    error: function st_asgeojson(public.geometry, integer) not exist

my understanding should search objects in search_path , find them in public schema doesn't happen reason. i've tried specifying search path on user level still didn't work.

the parameter name currentschema bit misleading. takes whole search_path, not "current schema". the documentation:

  • currentschema = string

specify schema set in search-path. schema used resolve unqualified object names used in statements on connection.

so try:

jdbc:postgresql://localhost:5432/tst?currentschema=app1,public 

or, if connect particular user, can set search_path user in db (or user in database). don't need in connection string.

or, if user name happens app1, search path setting "$user", public resolves app1, public automatically, , don't need anything extra.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -