Skip to content

Commit 7da5302

Browse files
authored
Issue 386: Do not call quote_ident() within repack_one_database() (#387)
It isn't necessary to call `quote_ident()` within `repack_one_database()`. `tablespace_dest` is passed to `repack.create_table()`, which already calls `quote_ident()`. `quote_ident()` within `repack_one_database()` can return quoted `tablespace_dest`, calling `quote_ident()` second time will make unexpected tablespace name with surrounding quotes. Tests were added.
1 parent 6a3c282 commit 7da5302

9 files changed

+260
-6
lines changed

.github/workflows/regression.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ jobs:
3434
- name: Put pg_repack on PATH
3535
run: echo "$PWD/bin" >> $GITHUB_PATH
3636

37-
- name: Create testts directory
38-
run: sudo -u postgres mkdir /tmp/testts
39-
40-
- name: Create testts tablespace
41-
run: sudo -u postgres psql -c "CREATE TABLESPACE testts LOCATION '/tmp/testts'"
37+
- name: Create tablespaces
38+
run: bash regress/create_tablespaces.sh
4239

4340
- name: Test on PostgreSQL ${{ matrix.pg }}
4441
run: pg-build-test

bin/pg_repack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
783783
"SELECT t.*,"
784784
" coalesce(v.tablespace, t.tablespace_orig) as tablespace_dest"
785785
" FROM repack.tables t, "
786-
" (VALUES (quote_ident($1::text))) as v (tablespace)"
786+
" (VALUES ($1::text)) as v (tablespace)"
787787
" WHERE ");
788788

789789
params[iparam++] = tablespace;

regress/create_tablespaces.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
sudo -u postgres mkdir /tmp/testts /tmp/1testts /tmp/test\ ts /tmp/test\"ts
4+
5+
sudo -u postgres psql -c "CREATE TABLESPACE testts LOCATION '/tmp/testts'"
6+
sudo -u postgres psql -c "CREATE TABLESPACE \"1testts\" LOCATION '/tmp/1testts'"
7+
sudo -u postgres psql -c "CREATE TABLESPACE \"test ts\" LOCATION '/tmp/test ts'"
8+
sudo -u postgres psql -c "CREATE TABLESPACE \"test\"\"ts\" LOCATION '/tmp/test\"ts'"

regress/expected/tablespace.out

+45
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,48 @@ ORDER BY relname;
245245
--using --indexes-only and --index option together
246246
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey
247247
ERROR: cannot specify --index (-i) and --table (-t)
248+
--check quote_ident() with 1testts tablespace
249+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx
250+
INFO: repacking table "public.testts1"
251+
SELECT relname, spcname
252+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
253+
WHERE relname ~ '^testts1'
254+
ORDER BY relname;
255+
relname | spcname
256+
---------------------+---------
257+
testts1 | 1testts
258+
testts1_partial_idx | 1testts
259+
testts1_pkey | 1testts
260+
testts1_with_idx | 1testts
261+
(4 rows)
262+
263+
--check quote_ident() with "test ts" tablespace
264+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx
265+
INFO: repacking table "public.testts1"
266+
SELECT relname, spcname
267+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
268+
WHERE relname ~ '^testts1'
269+
ORDER BY relname;
270+
relname | spcname
271+
---------------------+---------
272+
testts1 | test ts
273+
testts1_partial_idx | test ts
274+
testts1_pkey | test ts
275+
testts1_with_idx | test ts
276+
(4 rows)
277+
278+
--check quote_ident() with "test""ts" tablespace
279+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx
280+
INFO: repacking table "public.testts1"
281+
SELECT relname, spcname
282+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
283+
WHERE relname ~ '^testts1'
284+
ORDER BY relname;
285+
relname | spcname
286+
---------------------+---------
287+
testts1 | test"ts
288+
testts1_partial_idx | test"ts
289+
testts1_pkey | test"ts
290+
testts1_with_idx | test"ts
291+
(4 rows)
292+

regress/expected/tablespace_1.out

+45
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,48 @@ ORDER BY relname;
245245
--using --indexes-only and --index option together
246246
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey
247247
ERROR: cannot specify --index (-i) and --table (-t)
248+
--check quote_ident() with 1testts tablespace
249+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx
250+
INFO: repacking table "public.testts1"
251+
SELECT relname, spcname
252+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
253+
WHERE relname ~ '^testts1'
254+
ORDER BY relname;
255+
relname | spcname
256+
---------------------+---------
257+
testts1 | 1testts
258+
testts1_partial_idx | 1testts
259+
testts1_pkey | 1testts
260+
testts1_with_idx | 1testts
261+
(4 rows)
262+
263+
--check quote_ident() with "test ts" tablespace
264+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx
265+
INFO: repacking table "public.testts1"
266+
SELECT relname, spcname
267+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
268+
WHERE relname ~ '^testts1'
269+
ORDER BY relname;
270+
relname | spcname
271+
---------------------+---------
272+
testts1 | test ts
273+
testts1_partial_idx | test ts
274+
testts1_pkey | test ts
275+
testts1_with_idx | test ts
276+
(4 rows)
277+
278+
--check quote_ident() with "test""ts" tablespace
279+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx
280+
INFO: repacking table "public.testts1"
281+
SELECT relname, spcname
282+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
283+
WHERE relname ~ '^testts1'
284+
ORDER BY relname;
285+
relname | spcname
286+
---------------------+---------
287+
testts1 | test"ts
288+
testts1_partial_idx | test"ts
289+
testts1_pkey | test"ts
290+
testts1_with_idx | test"ts
291+
(4 rows)
292+

regress/expected/tablespace_2.out

+45
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,48 @@ ORDER BY relname;
245245
--using --indexes-only and --index option together
246246
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey
247247
ERROR: cannot specify --index (-i) and --table (-t)
248+
--check quote_ident() with 1testts tablespace
249+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx
250+
INFO: repacking table "public.testts1"
251+
SELECT relname, spcname
252+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
253+
WHERE relname ~ '^testts1'
254+
ORDER BY relname;
255+
relname | spcname
256+
---------------------+---------
257+
testts1 | 1testts
258+
testts1_partial_idx | 1testts
259+
testts1_pkey | 1testts
260+
testts1_with_idx | 1testts
261+
(4 rows)
262+
263+
--check quote_ident() with "test ts" tablespace
264+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx
265+
INFO: repacking table "public.testts1"
266+
SELECT relname, spcname
267+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
268+
WHERE relname ~ '^testts1'
269+
ORDER BY relname;
270+
relname | spcname
271+
---------------------+---------
272+
testts1 | test ts
273+
testts1_partial_idx | test ts
274+
testts1_pkey | test ts
275+
testts1_with_idx | test ts
276+
(4 rows)
277+
278+
--check quote_ident() with "test""ts" tablespace
279+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx
280+
INFO: repacking table "public.testts1"
281+
SELECT relname, spcname
282+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
283+
WHERE relname ~ '^testts1'
284+
ORDER BY relname;
285+
relname | spcname
286+
---------------------+---------
287+
testts1 | test"ts
288+
testts1_partial_idx | test"ts
289+
testts1_pkey | test"ts
290+
testts1_with_idx | test"ts
291+
(4 rows)
292+

regress/expected/tablespace_3.out

+45
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,48 @@ ORDER BY relname;
245245
--using --indexes-only and --index option together
246246
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey
247247
ERROR: cannot specify --index (-i) and --table (-t)
248+
--check quote_ident() with 1testts tablespace
249+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx
250+
INFO: repacking table "public.testts1"
251+
SELECT relname, spcname
252+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
253+
WHERE relname ~ '^testts1'
254+
ORDER BY relname;
255+
relname | spcname
256+
---------------------+---------
257+
testts1 | 1testts
258+
testts1_partial_idx | 1testts
259+
testts1_pkey | 1testts
260+
testts1_with_idx | 1testts
261+
(4 rows)
262+
263+
--check quote_ident() with "test ts" tablespace
264+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx
265+
INFO: repacking table "public.testts1"
266+
SELECT relname, spcname
267+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
268+
WHERE relname ~ '^testts1'
269+
ORDER BY relname;
270+
relname | spcname
271+
---------------------+---------
272+
testts1 | test ts
273+
testts1_partial_idx | test ts
274+
testts1_pkey | test ts
275+
testts1_with_idx | test ts
276+
(4 rows)
277+
278+
--check quote_ident() with "test""ts" tablespace
279+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx
280+
INFO: repacking table "public.testts1"
281+
SELECT relname, spcname
282+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
283+
WHERE relname ~ '^testts1'
284+
ORDER BY relname;
285+
relname | spcname
286+
---------------------+---------
287+
testts1 | test"ts
288+
testts1_partial_idx | test"ts
289+
testts1_pkey | test"ts
290+
testts1_with_idx | test"ts
291+
(4 rows)
292+

regress/expected/tablespace_4.out

+45
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,48 @@ ORDER BY relname;
245245
--using --indexes-only and --index option together
246246
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey
247247
ERROR: cannot specify --index (-i) and --table (-t)
248+
--check quote_ident() with 1testts tablespace
249+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx
250+
INFO: repacking table "public.testts1"
251+
SELECT relname, spcname
252+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
253+
WHERE relname ~ '^testts1'
254+
ORDER BY relname;
255+
relname | spcname
256+
---------------------+---------
257+
testts1 | 1testts
258+
testts1_partial_idx | 1testts
259+
testts1_pkey | 1testts
260+
testts1_with_idx | 1testts
261+
(4 rows)
262+
263+
--check quote_ident() with "test ts" tablespace
264+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx
265+
INFO: repacking table "public.testts1"
266+
SELECT relname, spcname
267+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
268+
WHERE relname ~ '^testts1'
269+
ORDER BY relname;
270+
relname | spcname
271+
---------------------+---------
272+
testts1 | test ts
273+
testts1_partial_idx | test ts
274+
testts1_pkey | test ts
275+
testts1_with_idx | test ts
276+
(4 rows)
277+
278+
--check quote_ident() with "test""ts" tablespace
279+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx
280+
INFO: repacking table "public.testts1"
281+
SELECT relname, spcname
282+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
283+
WHERE relname ~ '^testts1'
284+
ORDER BY relname;
285+
relname | spcname
286+
---------------------+---------
287+
testts1 | test"ts
288+
testts1_partial_idx | test"ts
289+
testts1_pkey | test"ts
290+
testts1_with_idx | test"ts
291+
(4 rows)
292+

regress/sql/tablespace.sql

+24
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,27 @@ ORDER BY relname;
147147

148148
--using --indexes-only and --index option together
149149
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey
150+
151+
--check quote_ident() with 1testts tablespace
152+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx
153+
154+
SELECT relname, spcname
155+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
156+
WHERE relname ~ '^testts1'
157+
ORDER BY relname;
158+
159+
--check quote_ident() with "test ts" tablespace
160+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx
161+
162+
SELECT relname, spcname
163+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
164+
WHERE relname ~ '^testts1'
165+
ORDER BY relname;
166+
167+
--check quote_ident() with "test""ts" tablespace
168+
\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx
169+
170+
SELECT relname, spcname
171+
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
172+
WHERE relname ~ '^testts1'
173+
ORDER BY relname;

0 commit comments

Comments
 (0)