On Friday, July 24, 2020 at 7:10:26 AM UTC-7, Jeremy Evans wrote:
>
> On Thursday, July 23, 2020 at 5:39:45 PM UTC-7, andy schmidt wrote:
>>
>> The Postgres primary_key_sequence method caches the results of the 
>> sequence lookup. If an unqualified table name is passed in it will store 
>> the unqualified table name as the cache lookup key with the schema 
>> qualified sequence as the value. If the search_path is changed to a 
>> different schema and the primary_key_sequence method called again with an 
>> unqualified table name it will return the sequence name qualified with the 
>> previous schema. Is this a bug or maybe I am misusing the method?
>>
>
> This isn't a bug, because support for changing the search_path at runtime 
> wasn't planned.  I suppose you could say it is a limitation. There are 
> plenty of other database changes you can make at runtime by directly 
> running SQL in the database that will result in Sequel returning the wrong 
> data due to caching:
>
>   DB.schema(:foo) # Sequel::DatabaseError
>   DB.run "CREATE TABLE foo(id integer)"
>   DB.schema(:foo) # no error
>   DB.run "DROP TABLE foo"
>   DB.schema(:foo) # no error
>
> In the above case, if you use Sequel's methods (DB.create_table, 
> DB.drop_table), things are handled properly. I suppose I could add a method 
> for changing the search path that would clear the related caches.
>

Actually, this isn't possible to do.  You can only change the search path 
on a per-connection basis.  The approach you are taking will not work 
correctly in a multithreaded environment with Sequel's default connection 
pool, since the search path will only be changed on a single connection. If 
you are going to use different search_paths in your application, you should 
use different Sequel::Database objects, not attempt to change the 
search_path for a Sequel::Database object at runtime.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/2ad2a2a6-2684-4266-85aa-627046c009dfo%40googlegroups.com.

Reply via email to