Error on invalid TOAST compression in CREATE or ALTER TABLE.
authorRobert Haas <rhaas@postgresql.org>
Mon, 22 Mar 2021 14:57:08 +0000 (10:57 -0400)
committerRobert Haas <rhaas@postgresql.org>
Mon, 22 Mar 2021 14:57:08 +0000 (10:57 -0400)
The previous coding treated an invalid compression method name as
equivalent to the default, which is certainly not right.

Justin Pryzby

Discussion: http://postgr.es/m/20210321235544.GD4203@telsasoft.com

src/backend/commands/tablecmds.c
src/test/regress/expected/compression.out
src/test/regress/expected/compression_1.out
src/test/regress/sql/compression.sql

index 22f3c5efc09957d57d92a4136b6f55cd74c92740..54fea31e43fd6700ea639cd7e4683984f6a7ed95 100644 (file)
@@ -17863,9 +17863,13 @@ GetAttributeCompression(Form_pg_attribute att, char *compression)
 
    /* fallback to default compression if it's not specified */
    if (compression == NULL)
-       cmethod = GetDefaultToastCompression();
-   else
-       cmethod = CompressionNameToMethod(compression);
+       return GetDefaultToastCompression();
+
+   cmethod = CompressionNameToMethod(compression);
+   if (!CompressionMethodIsValid(cmethod))
+       ereport(ERROR,
+               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                errmsg("invalid compression method \"%s\"", compression)));
 
    return cmethod;
 }
index 18ac5f05bbddb9f4a5db184fd038e913ba8c7170..c2f2e0e230ba706b5b4008546319d5959d5b8508 100644 (file)
@@ -347,4 +347,10 @@ SELECT length(f1) FROM cmmove3;
   10040
 (2 rows)
 
+CREATE TABLE badcompresstbl (a text COMPRESSION I_Do_Not_Exist_Compression); -- fails
+ERROR:  invalid compression method "i_do_not_exist_compression"
+CREATE TABLE badcompresstbl (a text);
+ALTER TABLE badcompresstbl ALTER a SET COMPRESSION I_Do_Not_Exist_Compression; -- fails
+ERROR:  invalid compression method "i_do_not_exist_compression"
+DROP TABLE badcompresstbl;
 \set HIDE_TOAST_COMPRESSION true
index c4a2cea4cd8e637a5fc5b8ce4d4c86015075fd3a..6626f8e9272022c07dcdeeeb2c08670b76b053c0 100644 (file)
@@ -340,4 +340,10 @@ SELECT length(f1) FROM cmmove3;
   10000
 (1 row)
 
+CREATE TABLE badcompresstbl (a text COMPRESSION I_Do_Not_Exist_Compression); -- fails
+ERROR:  invalid compression method "i_do_not_exist_compression"
+CREATE TABLE badcompresstbl (a text);
+ALTER TABLE badcompresstbl ALTER a SET COMPRESSION I_Do_Not_Exist_Compression; -- fails
+ERROR:  invalid compression method "i_do_not_exist_compression"
+DROP TABLE badcompresstbl;
 \set HIDE_TOAST_COMPRESSION true
index e23669cc94cd3ccbb91d7b4887b5d64860fc3aa9..5e178be04a2cb0fd5c1a20cd4e3bd4e091a25798 100644 (file)
@@ -137,4 +137,9 @@ SELECT length(f1) FROM cmmove1;
 SELECT length(f1) FROM cmmove2;
 SELECT length(f1) FROM cmmove3;
 
+CREATE TABLE badcompresstbl (a text COMPRESSION I_Do_Not_Exist_Compression); -- fails
+CREATE TABLE badcompresstbl (a text);
+ALTER TABLE badcompresstbl ALTER a SET COMPRESSION I_Do_Not_Exist_Compression; -- fails
+DROP TABLE badcompresstbl;
+
 \set HIDE_TOAST_COMPRESSION true