Fixed index definition tokenization
In the previous commit skip_const was going ahead the space thus removing the starting quote. Also fixed (and tested) trailing part after the tablespace name, e.g. the WHERE clause.
This commit is contained in:
parent
83fdb2a9e0
commit
d98a14bb55
@ -12,6 +12,7 @@ SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
|
|||||||
|
|
||||||
-- If the query above failed you must create the 'testts' tablespace;
|
-- If the query above failed you must create the 'testts' tablespace;
|
||||||
CREATE TABLE testts1 (id serial primary key, data text);
|
CREATE TABLE testts1 (id serial primary key, data text);
|
||||||
|
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
|
||||||
INSERT INTO testts1 (data) values ('a');
|
INSERT INTO testts1 (data) values ('a');
|
||||||
INSERT INTO testts1 (data) values ('b');
|
INSERT INTO testts1 (data) values ('b');
|
||||||
INSERT INTO testts1 (data) values ('c');
|
INSERT INTO testts1 (data) values ('c');
|
||||||
@ -19,7 +20,8 @@ INSERT INTO testts1 (data) values ('c');
|
|||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1'
|
||||||
|
ORDER BY relname;
|
||||||
relname | spcname
|
relname | spcname
|
||||||
---------+---------
|
---------+---------
|
||||||
testts1 | testts
|
testts1 | testts
|
||||||
@ -37,7 +39,8 @@ SELECT * from testts1 order by id;
|
|||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1'
|
||||||
|
ORDER BY relname;
|
||||||
relname | spcname
|
relname | spcname
|
||||||
---------+---------
|
---------+---------
|
||||||
testts1 | testts
|
testts1 | testts
|
||||||
@ -47,7 +50,8 @@ WHERE relname ~ '^testts1';
|
|||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1'
|
||||||
|
ORDER BY relname;
|
||||||
relname | spcname
|
relname | spcname
|
||||||
---------+---------
|
---------+---------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
@ -56,12 +60,14 @@ WHERE relname ~ '^testts1';
|
|||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1'
|
||||||
relname | spcname
|
ORDER BY relname;
|
||||||
--------------+---------
|
relname | spcname
|
||||||
testts1 | testts
|
---------------------+---------
|
||||||
testts1_pkey | testts
|
testts1 | testts
|
||||||
(2 rows)
|
testts1_partial_idx | testts
|
||||||
|
testts1_pkey | testts
|
||||||
|
(3 rows)
|
||||||
|
|
||||||
-- can't specify --moveidx without --tablespace
|
-- can't specify --moveidx without --tablespace
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx
|
||||||
|
@ -10,6 +10,7 @@ SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
|
|||||||
-- If the query above failed you must create the 'testts' tablespace;
|
-- If the query above failed you must create the 'testts' tablespace;
|
||||||
|
|
||||||
CREATE TABLE testts1 (id serial primary key, data text);
|
CREATE TABLE testts1 (id serial primary key, data text);
|
||||||
|
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
|
||||||
INSERT INTO testts1 (data) values ('a');
|
INSERT INTO testts1 (data) values ('a');
|
||||||
INSERT INTO testts1 (data) values ('b');
|
INSERT INTO testts1 (data) values ('b');
|
||||||
INSERT INTO testts1 (data) values ('c');
|
INSERT INTO testts1 (data) values ('c');
|
||||||
@ -19,7 +20,8 @@ INSERT INTO testts1 (data) values ('c');
|
|||||||
|
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1'
|
||||||
|
ORDER BY relname;
|
||||||
|
|
||||||
SELECT * from testts1 order by id;
|
SELECT * from testts1 order by id;
|
||||||
|
|
||||||
@ -28,21 +30,24 @@ SELECT * from testts1 order by id;
|
|||||||
|
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1'
|
||||||
|
ORDER BY relname;
|
||||||
|
|
||||||
-- can move the ts back to default
|
-- can move the ts back to default
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
|
||||||
|
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1'
|
||||||
|
ORDER BY relname;
|
||||||
|
|
||||||
-- can move the table together with the indexes
|
-- can move the table together with the indexes
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
|
||||||
|
|
||||||
SELECT relname, spcname
|
SELECT relname, spcname
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
||||||
WHERE relname ~ '^testts1';
|
WHERE relname ~ '^testts1'
|
||||||
|
ORDER BY relname;
|
||||||
|
|
||||||
-- can't specify --moveidx without --tablespace
|
-- can't specify --moveidx without --tablespace
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx
|
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx
|
||||||
|
15
lib/repack.c
15
lib/repack.c
@ -653,8 +653,7 @@ repack_indexdef(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *pos;
|
if (NULL == strstr(stmt.options, "TABLESPACE"))
|
||||||
if (NULL == (pos = strstr(stmt.options, " TABLESPACE ")))
|
|
||||||
{
|
{
|
||||||
/* tablespace is to append */
|
/* tablespace is to append */
|
||||||
appendStringInfoString(&str, " TABLESPACE ");
|
appendStringInfoString(&str, " TABLESPACE ");
|
||||||
@ -662,16 +661,14 @@ repack_indexdef(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
/* tablespace is to replace */
|
/* tablespace is to replace */
|
||||||
tmp = skip_const(index, stmt.options, " TABLESPACE ", NULL);
|
char *tmp;
|
||||||
|
tmp = skip_const(index, stmt.options, " TABLESPACE", NULL);
|
||||||
appendStringInfoString(&str, stmt.options);
|
appendStringInfoString(&str, stmt.options);
|
||||||
appendStringInfoString(&str, NameStr(*tablespace));
|
appendStringInfo(&str, " %s", NameStr(*tablespace));
|
||||||
/* FIXME: not working if original ts has a space. But skip_ident
|
|
||||||
* should deal with that. Stupid mistake somewhere? */
|
|
||||||
tmp = skip_ident(index, tmp);
|
tmp = skip_ident(index, tmp);
|
||||||
appendStringInfoString(&str, tmp);
|
if (*tmp)
|
||||||
|
appendStringInfo(&str, " %s", tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user