How to use search_path in CASE

Поиск
Список
Период
Сортировка
От Lennart Ripke
Тема How to use search_path in CASE
Дата
Msg-id 43B631B7D85C9041AE58B7834DFF6A751F2298@server.Auto.local
обсуждение исходный текст
Ответы Re: How to use search_path in CASE  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: How to use search_path in CASE  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список pgsql-novice

Hello!

 

I have a database with 6 schemas (named schema1 to schema6), each contains a table ‘foo’. I want to insert testvalues into these tables using a plpgsql function.

 

Something like:

 

For s in 1..6 LOOP

  CASE s

    WHEN 1 THEN

      SET LOCAL search_path TO schema1;

    WHEN 2 THEN

      SET LOCAL search_path TO schema2;

    WHEN 3 THEN

      SET LOCAL search_path TO schema3;

    WHEN 4 THEN

      SET LOCAL search_path TO schema4;

    WHEN 5 THEN

      SET LOCAL search_path TO schema5;

    WHEN 6 THEN

      SET LOCAL search_path TO schema6;

  END CASE;

 

  INSERT INTO foo (...) VALUES (...);

END LOOP;

 

This does not work. All values are directed into table ‘schema1.foo’.

 

I learned you can’t use SET search_path  (or SET LOCAL) in a CASE structure because the function is using the current search path , which does only change at session scope.

But how to accomplish this task? I don’t want to put the INSERT statement into the CASE structure for reasons of clarity and readability.

 

Best regards, Lennart

В списке pgsql-novice по дате отправления:

Предыдущее
От: David Jarvis
Дата:
Сообщение: Re: Invalid syntax for integer
Следующее
От: Tom Lane
Дата:
Сообщение: Re: How to use search_path in CASE