Re: alter multiple tables

Поиск
Список
Период
Сортировка
От dcrespo
Тема Re: alter multiple tables
Дата
Msg-id a86689d1-a9f3-46fe-a2df-8171c46f8bf4@z1g2000yqn.googlegroups.com
обсуждение исходный текст
Ответ на alter multiple tables  ("Kodok Marton" <marton@mybusinessanywhere.com>)
Список pgsql-general
On Mar 16, 12:08 pm, t...@wildenhain.de (Tino Wildenhain) wrote:
> > Since I have a lot of tables and mirrored backups, I am wondering if
> > there is a way to alter automatically all tables where colname matches
> > 'username'
> > Is there a way to do this?

Enter psql with '-E' flag, and see the query that is generated when
using commands like '\dt' (which is for showing the tables in the
current database).

For example:
-bash-3.1$ psql -U some_user -d test_db -E
Welcome to psql 8.2.1, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

eds_db=# \dt
********* QUERY **********
SELECT n.nspname as "Schema",
  c.relname as "Name",
  CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i'
THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as
"Type",
  r.rolname as "Owner"
FROM pg_catalog.pg_class c
     JOIN pg_catalog.pg_roles r ON r.oid = c.relowner
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
      AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
**************************

       List of relations
 Schema | Name | Type  | Owner
--------+------+-------+--------
 public | test | table | some_user

Use the generated query, and modify it to suit your needs. There are
ways of extracting the columns from a given table name. With that, do
a for loop.

Daniel

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

Предыдущее
От: John R Pierce
Дата:
Сообщение: Re: deployment query
Следующее
От: "Nagalingam, Karthikeyan"
Дата:
Сообщение: Re: deployment query