wrong error message related to unsupported feature

Started by Pavel Stehuleover 1 year ago4 messageshackers

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
1 day ago

@global #bug

#bug
Jump to latest
#1Pavel Stehule
pavel.stehule@gmail.com

Hi

I am playing with new features in Postgres 18.

Maybe I found a bug

(2025-03-18 19:28:06) postgres=# create table foo(a int constraint gzero
check(a > 10) NOT ENFORCED);
CREATE TABLE
(2025-03-18 19:29:37) postgres=# insert into foo values(0);
INSERT 0 1
(2025-03-18 19:29:49) postgres=# insert into foo values(6);
INSERT 0 1
(2025-03-18 19:29:55) postgres=# alter table foo alter constraint gzero
enforced;
ERROR: FOREIGN KEY constraints cannot be marked ENFORCED
LINE 1: alter table foo alter constraint gzero enforced;

I know so altering enforcing constraint is not supported yet, but the error
message is surely wrong

gzero is not foreign key constraint

Regards

Pavel

#2Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Pavel Stehule (#1)
Re: wrong error message related to unsupported feature

On 2025-Mar-18, Pavel Stehule wrote:

Maybe I found a bug

(2025-03-18 19:28:06) postgres=# create table foo(a int constraint gzero
check(a > 10) NOT ENFORCED);
CREATE TABLE
(2025-03-18 19:29:37) postgres=# insert into foo values(0);
INSERT 0 1
(2025-03-18 19:29:49) postgres=# insert into foo values(6);
INSERT 0 1
(2025-03-18 19:29:55) postgres=# alter table foo alter constraint gzero
enforced;
ERROR: FOREIGN KEY constraints cannot be marked ENFORCED
LINE 1: alter table foo alter constraint gzero enforced;

I know so altering enforcing constraint is not supported yet, but the error
message is surely wrong

Yep, this is a bug all right -- I reported this and related problems a
few days ago [1]/messages/by-id/202503041822.aobpqke3igvb@alvherre.pgsql. There's a proposal in that thread for how to fix this
(see Amul's email [2]/messages/by-id/CAAJ_b97hd-jMTS7AjgU6TDBCzDx_KyuKxG+K-DtYmOieg+giyQ@mail.gmail.com and my followup), but I haven't had time to fully
implement it. If you want to give it a couple of hours to complete it,
that'd be great. I have a couple of patches that I need to handle
before coming back to that.

[1]: /messages/by-id/202503041822.aobpqke3igvb@alvherre.pgsql
[2]: /messages/by-id/CAAJ_b97hd-jMTS7AjgU6TDBCzDx_KyuKxG+K-DtYmOieg+giyQ@mail.gmail.com

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#2)
Re: wrong error message related to unsupported feature

Hi

út 18. 3. 2025 v 21:33 odesílatel Álvaro Herrera <alvherre@alvh.no-ip.org>
napsal:

On 2025-Mar-18, Pavel Stehule wrote:

Maybe I found a bug

(2025-03-18 19:28:06) postgres=# create table foo(a int constraint gzero
check(a > 10) NOT ENFORCED);
CREATE TABLE
(2025-03-18 19:29:37) postgres=# insert into foo values(0);
INSERT 0 1
(2025-03-18 19:29:49) postgres=# insert into foo values(6);
INSERT 0 1
(2025-03-18 19:29:55) postgres=# alter table foo alter constraint gzero
enforced;
ERROR: FOREIGN KEY constraints cannot be marked ENFORCED
LINE 1: alter table foo alter constraint gzero enforced;

I know so altering enforcing constraint is not supported yet, but the

error

message is surely wrong

Yep, this is a bug all right -- I reported this and related problems a
few days ago [1]. There's a proposal in that thread for how to fix this
(see Amul's email [2] and my followup), but I haven't had time to fully
implement it. If you want to give it a couple of hours to complete it,
that'd be great. I have a couple of patches that I need to handle
before coming back to that.

[1] /messages/by-id/202503041822.aobpqke3igvb@alvherre.pgsql
[2]
/messages/by-id/CAAJ_b97hd-jMTS7AjgU6TDBCzDx_KyuKxG+K-DtYmOieg+giyQ@mail.gmail.com

I am looking this issue, and I am not sure if proposed way is the best

cannot we change processCASbits just like ?

if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
{
if (deferrable)
*deferrable = true;
else if (constrType)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
/* translator: %s is CHECK, UNIQUE, or similar */
constrType ?
errmsg("%s constraints cannot be marked DEFERRABLE",
constrType) :
errmsg("constraint cannot be marked DEFERRABLE"),
parser_errposition(location)));
}
...

Probably can be better to not try to read from catalog in this moment, and
then we can accept so we don't know constraint type

Regards

Pavel

Show quoted text

--
Álvaro Herrera PostgreSQL Developer —
https://www.EnterpriseDB.com/

#4Pavel Stehule
pavel.stehule@gmail.com
In reply to: Pavel Stehule (#3)
Re: wrong error message related to unsupported feature

čt 20. 3. 2025 v 22:30 odesílatel Pavel Stehule <pavel.stehule@gmail.com>
napsal:

Hi

út 18. 3. 2025 v 21:33 odesílatel Álvaro Herrera <alvherre@alvh.no-ip.org>
napsal:

On 2025-Mar-18, Pavel Stehule wrote:

Maybe I found a bug

(2025-03-18 19:28:06) postgres=# create table foo(a int constraint gzero
check(a > 10) NOT ENFORCED);
CREATE TABLE
(2025-03-18 19:29:37) postgres=# insert into foo values(0);
INSERT 0 1
(2025-03-18 19:29:49) postgres=# insert into foo values(6);
INSERT 0 1
(2025-03-18 19:29:55) postgres=# alter table foo alter constraint gzero
enforced;
ERROR: FOREIGN KEY constraints cannot be marked ENFORCED
LINE 1: alter table foo alter constraint gzero enforced;

I know so altering enforcing constraint is not supported yet, but the

error

message is surely wrong

Yep, this is a bug all right -- I reported this and related problems a
few days ago [1]. There's a proposal in that thread for how to fix this
(see Amul's email [2] and my followup), but I haven't had time to fully
implement it. If you want to give it a couple of hours to complete it,
that'd be great. I have a couple of patches that I need to handle
before coming back to that.

[1] /messages/by-id/202503041822.aobpqke3igvb@alvherre.pgsql
[2]
/messages/by-id/CAAJ_b97hd-jMTS7AjgU6TDBCzDx_KyuKxG+K-DtYmOieg+giyQ@mail.gmail.com

I am looking this issue, and I am not sure if proposed way is the best

cannot we change processCASbits just like ?

if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
{
if (deferrable)
*deferrable = true;
else if (constrType)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
/* translator: %s is CHECK, UNIQUE, or similar */
constrType ?
errmsg("%s constraints cannot be marked DEFERRABLE",
constrType) :
errmsg("constraint cannot be marked DEFERRABLE"),
parser_errposition(location)));
}
...

Probably can be better to not try to read from catalog in this moment, and
then we can accept so we don't know constraint type

something like attached patch

Regards

Pavel

Show quoted text

Regards

Pavel

--
Álvaro Herrera PostgreSQL Developer —
https://www.EnterpriseDB.com/

Attachments:

t51262_4
fix-message.patchtext/x-patch; charset=US-ASCII; name=fix-message.patchDownload+29-17