Skip to content

Commit 1f5b1fe

Browse files
committed
update_from_4.3_new_commerce.md: Drop old tables: PostgreSQL query
1 parent 88f1685 commit 1f5b1fe

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

docs/update_and_migration/from_4.3/update_from_4.3_new_commerce.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -343,30 +343,29 @@ The removable table are prefixed with `ses_` and `sve_`.
343343

344344
=== "PostgreSQL"
345345

346+
To list the removable tables:
346347
```sql
347-
SHOW TABLES FROM <database_name> WHERE Tables_in_<database_name> LIKE 'ses_%' OR Tables_in_<database_name> LIKE 'sve_%';
348+
SELECT tableowner, tablename
349+
FROM pg_catalog.pg_tables
350+
WHERE schemaname='public' AND tableowner='<database_name>' AND (tablename LIKE 'ses_%' OR tablename LIKE 'sve_%');
348351
```
349352

353+
To loop through the tables to drop them (be sure to use the right database with `\connect <database_name>;`.):
350354
```sql
351-
FOR table_row IN
352-
SELECT
353-
table_schema,
354-
table_name
355-
FROM
356-
information_schema.tables
357-
WHERE
358-
table_type = 'BASE TABLE'
359-
AND
360-
table_schema = '<database_name>'
361-
AND
362-
(
363-
table_name LIKE ('ses_%')
364-
OR
365-
table_name LIKE ('sve_%')
366-
)
367-
LOOP
368-
EXECUTE 'DROP TABLE ' || table_row.table_schema || '.' || table_row.table_name;
369-
END LOOP;
355+
DO $drop$
356+
DECLARE table_row RECORD;
357+
BEGIN
358+
FOR table_row IN
359+
SELECT table_catalog, table_name
360+
FROM information_schema.tables
361+
WHERE table_schema = 'public' AND table_type = 'BASE TABLE'
362+
AND table_catalog = 'db' AND (table_name LIKE ('ses_%') OR table_name LIKE ('sve_%'))
363+
LOOP
364+
EXECUTE 'DROP TABLE ' || table_row.table_name;
365+
END LOOP
366+
;
367+
END
368+
$drop$;
370369
```
371370

372371
#### Ibexa Open Source

0 commit comments

Comments
 (0)