[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    Re: [postgis-users] Repeat operations on 50 tables of the same schema?
From:       Bo Victor Thomsen <bo.victor.thomsen () gmail ! com>
Date:       2023-03-02 8:30:02
Message-ID: 5b66f59b-da60-ce5c-dd67-66f3f213281e () gmail ! com
[Download RAW message or body]

As other has mentioned: Use the information_schema.tables:

SELECT CONCAT('ALTER TABLE "',table_schema,'"."',table_name,'" RENAME TO 
"IGN_bdTopo_',table_name,'_V1";') AS SQL FROM information_schema.tables
WHERE table_schema = 'ign'

The result from this select is a list of SQL commands to rename each 
table in schema "ign" to another name. You can apply the same method to 
generate other "ALTER" commands. Google "postgres alter table"

By the way - It's a bad habit to have mixed-case table identifiers (Just 
my 2 cents)


Med venlig hilsen / Best regards

Bo Victor Thomsen

Den 27-02-2023 kl. 11:49 skrev celati Laurent:
> Good morning,
> I am new to Postgresql. I have 50 tables into a "ign" schema (schema 
> other than public).
> I would like for each of these 50 tables:
>
> - Add a prefix to the name of the table: "IGN_bdTopo_"
> - Add a suffix to the table name: "_V1"
> - create a new "date" column of date type. And populate this field 
> with the value: 06/15/2021
> - create a new "source" column of type varchar (length 50). And 
> populate this field with the value: 'ign'.
> - move all the elements of these 50 tables (including all). from the 
> "ign" schema to the "ign_v2" schema. Whether data, constraints, indexes.
>
> If someone could   help me? Thank you so much.
>
> _______________________________________________
> postgis-users mailing list
> postgis-users@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
postgis-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/postgis-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic