public inbox for [email protected]
help / color / mirror / Atom feedBug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
9+ messages / 5 participants
[nested] [flat]
* Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
@ 2021-04-27 00:24 David Fetter <[email protected]>
0 siblings, 1 reply; 9+ messages in thread
From: David Fetter @ 2021-04-27 00:24 UTC (permalink / raw)
To: pgsql-hackers
Folks,
I noticed that $subject completes with already valid constraints,
please find attached a patch that fixes it. I noticed that there are
other places constraints can be validated, but didn't check whether
similar bugs exist there yet.
Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
@ 2021-04-27 09:33 Aleksander Alekseev <[email protected]>
parent: David Fetter <[email protected]>
0 siblings, 2 replies; 9+ messages in thread
From: Aleksander Alekseev @ 2021-04-27 09:33 UTC (permalink / raw)
To: David Fetter <[email protected]>; +Cc: pgsql-hackers
Hi David,
> I noticed that $subject completes with already valid constraints,
> please find attached a patch that fixes it. I noticed that there are
> other places constraints can be validated, but didn't check whether
> similar bugs exist there yet.
There was a typo in the patch ("... and and not convalidated"). I've fixed
it. Otherwise the patch passes all the tests and works as expected:
eax=# create table foo (x int);
CREATE TABLE
eax=# alter table foo add constraint bar check (x < 3) not valid;
ALTER TABLE
eax=# alter table foo add constraint baz check (x <> 5) not valid;
ALTER TABLE
eax=# alter table foo validate constraint ba
bar baz
eax=# alter table foo validate constraint bar;
ALTER TABLE
--
Best regards,
Aleksander Alekseev
Attachments:
[application/octet-stream] v2-0001-tab-completion-of-ALTER-TABLE.VALIDATE-CONSTRAINT.patch (1.7K, ../../CAJ7c6TPjd5ARCdjabewO6mF13v9toMwv72+nc1fMERpkSY3qRQ@mail.gmail.com/3-v2-0001-tab-completion-of-ALTER-TABLE.VALIDATE-CONSTRAINT.patch)
download | inline diff:
diff --git src/bin/psql/tab-complete.c src/bin/psql/tab-complete.c
index 7c4933333b..b1bca24714 100644
--- src/bin/psql/tab-complete.c
+++ src/bin/psql/tab-complete.c
@@ -785,6 +785,15 @@ static const SchemaQuery Query_for_list_of_collations = {
" and pg_catalog.quote_ident(c1.relname)='%s'"\
" and pg_catalog.pg_table_is_visible(c1.oid)"
+/* the silly-looking length condition is just to eat up the current word */
+#define Query_for_nonvalid_constraint_of_table \
+"SELECT pg_catalog.quote_ident(conname) "\
+" FROM pg_catalog.pg_class c1, pg_catalog.pg_constraint con "\
+" WHERE c1.oid=conrelid and not convalidated"\
+" and (%d = pg_catalog.length('%s'))"\
+" and pg_catalog.quote_ident(c1.relname)='%s'"\
+" and pg_catalog.pg_table_is_visible(c1.oid)"
+
#define Query_for_all_table_constraints \
"SELECT pg_catalog.quote_ident(conname) "\
" FROM pg_catalog.pg_constraint c "\
@@ -2118,11 +2127,16 @@ psql_completion(const char *text, int start, int end)
* If we have ALTER TABLE <sth> ALTER|DROP|RENAME|VALIDATE CONSTRAINT,
* provide list of constraints
*/
- else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME|VALIDATE", "CONSTRAINT"))
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT"))
{
completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_constraint_of_table);
}
+ else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
+ {
+ completion_info_charp = prev3_wd;
+ COMPLETE_WITH_QUERY(Query_for_nonvalid_constraint_of_table);
+ }
/* ALTER TABLE ALTER [COLUMN] <foo> */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny) ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny))
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
@ 2021-04-27 09:58 Aleksander Alekseev <[email protected]>
parent: Aleksander Alekseev <[email protected]>
1 sibling, 1 reply; 9+ messages in thread
From: Aleksander Alekseev @ 2021-04-27 09:58 UTC (permalink / raw)
To: David Fetter <[email protected]>; +Cc: pgsql-hackers
Hi hackers,
> Otherwise the patch passes all the tests and works as expected
I've noticed there is no tab completion for ALTER TABLE xxx ADD. Here
is an alternative version of the patch that fixes this as well. Not
sure if this should be in the same commit though.
--
Best regards,
Aleksander Alekseev
Attachments:
[application/octet-stream] v3-0001-tab-completion-of-ALTER-TABLE.VALIDATE-CONSTRAINT.patch (2.3K, ../../CAJ7c6TNe+38Vgd3qMuGafjWP1A52cX9V5wbbExQu-iQpmi60kA@mail.gmail.com/2-v3-0001-tab-completion-of-ALTER-TABLE.VALIDATE-CONSTRAINT.patch)
download | inline diff:
diff --git src/bin/psql/tab-complete.c src/bin/psql/tab-complete.c
index 7c4933333b..b2b8431bc2 100644
--- src/bin/psql/tab-complete.c
+++ src/bin/psql/tab-complete.c
@@ -785,6 +785,15 @@ static const SchemaQuery Query_for_list_of_collations = {
" and pg_catalog.quote_ident(c1.relname)='%s'"\
" and pg_catalog.pg_table_is_visible(c1.oid)"
+/* the silly-looking length condition is just to eat up the current word */
+#define Query_for_nonvalid_constraint_of_table \
+"SELECT pg_catalog.quote_ident(conname) "\
+" FROM pg_catalog.pg_class c1, pg_catalog.pg_constraint con "\
+" WHERE c1.oid=conrelid and not convalidated"\
+" and (%d = pg_catalog.length('%s'))"\
+" and pg_catalog.quote_ident(c1.relname)='%s'"\
+" and pg_catalog.pg_table_is_visible(c1.oid)"
+
#define Query_for_all_table_constraints \
"SELECT pg_catalog.quote_ident(conname) "\
" FROM pg_catalog.pg_constraint c "\
@@ -2107,8 +2116,8 @@ psql_completion(const char *text, int start, int end)
else if (Matches("ALTER", "TABLE", MatchAny, "RENAME", "COLUMN|CONSTRAINT", MatchAnyExcept("TO")))
COMPLETE_WITH("TO");
- /* If we have ALTER TABLE <sth> DROP, provide COLUMN or CONSTRAINT */
- else if (Matches("ALTER", "TABLE", MatchAny, "DROP"))
+ /* If we have ALTER TABLE <sth> ADD|DROP, provide COLUMN or CONSTRAINT */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD|DROP"))
COMPLETE_WITH("COLUMN", "CONSTRAINT");
/* If we have ALTER TABLE <sth> DROP COLUMN, provide list of columns */
else if (Matches("ALTER", "TABLE", MatchAny, "DROP", "COLUMN"))
@@ -2118,11 +2127,16 @@ psql_completion(const char *text, int start, int end)
* If we have ALTER TABLE <sth> ALTER|DROP|RENAME|VALIDATE CONSTRAINT,
* provide list of constraints
*/
- else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME|VALIDATE", "CONSTRAINT"))
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT"))
{
completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_constraint_of_table);
}
+ else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
+ {
+ completion_info_charp = prev3_wd;
+ COMPLETE_WITH_QUERY(Query_for_nonvalid_constraint_of_table);
+ }
/* ALTER TABLE ALTER [COLUMN] <foo> */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny) ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny))
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
@ 2021-04-28 02:53 David Fetter <[email protected]>
parent: Aleksander Alekseev <[email protected]>
1 sibling, 0 replies; 9+ messages in thread
From: David Fetter @ 2021-04-28 02:53 UTC (permalink / raw)
To: Aleksander Alekseev <[email protected]>; +Cc: pgsql-hackers
On Tue, Apr 27, 2021 at 12:33:25PM +0300, Aleksander Alekseev wrote:
> Hi David,
>
> > I noticed that $subject completes with already valid constraints,
> > please find attached a patch that fixes it. I noticed that there are
> > other places constraints can be validated, but didn't check whether
> > similar bugs exist there yet.
>
> There was a typo in the patch ("... and and not convalidated"). I've fixed
> it. Otherwise the patch passes all the tests and works as expected:
>
> eax=# create table foo (x int);
> CREATE TABLE
> eax=# alter table foo add constraint bar check (x < 3) not valid;
> ALTER TABLE
> eax=# alter table foo add constraint baz check (x <> 5) not valid;
> ALTER TABLE
> eax=# alter table foo validate constraint ba
> bar baz
> eax=# alter table foo validate constraint bar;
> ALTER TABLE
Sorry about that typo, and thanks for poking at this!
Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
@ 2021-05-19 07:53 Michael Paquier <[email protected]>
parent: Aleksander Alekseev <[email protected]>
0 siblings, 1 reply; 9+ messages in thread
From: Michael Paquier @ 2021-05-19 07:53 UTC (permalink / raw)
To: Aleksander Alekseev <[email protected]>; +Cc: David Fetter <[email protected]>; pgsql-hackers
On Tue, Apr 27, 2021 at 12:58:52PM +0300, Aleksander Alekseev wrote:
> I've noticed there is no tab completion for ALTER TABLE xxx ADD. Here
> is an alternative version of the patch that fixes this as well. Not
> sure if this should be in the same commit though.
- /* If we have ALTER TABLE <sth> DROP, provide COLUMN or CONSTRAINT */
- else if (Matches("ALTER", "TABLE", MatchAny, "DROP"))
+ /* If we have ALTER TABLE <sth> ADD|DROP, provide COLUMN or CONSTRAINT */
+ else if (Matches("ALTER", "TABLE", MatchAny, "ADD|DROP"))
Seems to me that the behavior to not complete with COLUMN or
CONSTRAINT for ADD is intentional, as it is possible to specify a
constraint or column name without the object type first. This
introduces a inconsistent behavior with what we do for columns with
ADD, for one. So a more consistent approach would be to list columns,
constraints, COLUMN and CONSTRAINT in the list of options available
after ADD.
+ else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
+ {
+ completion_info_charp = prev3_wd;
+ COMPLETE_WITH_QUERY(Query_for_nonvalid_constraint_of_table);
+ }
Specifying valid constraints is an authorized grammar, so it does not
seem that bad to keep things as they are, either. I would leave that
alone.
--
Michael
Attachments:
[application/pgp-signature] signature.asc (833B, ../../YKTD7p%[email protected]/2-signature.asc)
download
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
@ 2021-09-03 18:27 Daniel Gustafsson <[email protected]>
parent: Michael Paquier <[email protected]>
0 siblings, 1 reply; 9+ messages in thread
From: Daniel Gustafsson @ 2021-09-03 18:27 UTC (permalink / raw)
To: Michael Paquier <[email protected]>; +Cc: Aleksander Alekseev <[email protected]>; David Fetter <[email protected]>; pgsql-hackers
> On 19 May 2021, at 09:53, Michael Paquier <[email protected]> wrote:
>
> On Tue, Apr 27, 2021 at 12:58:52PM +0300, Aleksander Alekseev wrote:
>> I've noticed there is no tab completion for ALTER TABLE xxx ADD. Here
>> is an alternative version of the patch that fixes this as well. Not
>> sure if this should be in the same commit though.
>
> - /* If we have ALTER TABLE <sth> DROP, provide COLUMN or CONSTRAINT */
> - else if (Matches("ALTER", "TABLE", MatchAny, "DROP"))
> + /* If we have ALTER TABLE <sth> ADD|DROP, provide COLUMN or CONSTRAINT */
> + else if (Matches("ALTER", "TABLE", MatchAny, "ADD|DROP"))
> Seems to me that the behavior to not complete with COLUMN or
> CONSTRAINT for ADD is intentional, as it is possible to specify a
> constraint or column name without the object type first. This
> introduces a inconsistent behavior with what we do for columns with
> ADD, for one. So a more consistent approach would be to list columns,
> constraints, COLUMN and CONSTRAINT in the list of options available
> after ADD.
>
> + else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
> + {
> + completion_info_charp = prev3_wd;
> + COMPLETE_WITH_QUERY(Query_for_nonvalid_constraint_of_table);
> + }
> Specifying valid constraints is an authorized grammar, so it does not
> seem that bad to keep things as they are, either. I would leave that
> alone.
This has stalled being marked Waiting on Author since May, and reading the
above it sounds like marking it Returned with Feedback is the logical next step
(patch also no longer applies).
--
Daniel Gustafsson https://vmware.com/
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
@ 2021-09-15 06:06 David Fetter <[email protected]>
parent: Daniel Gustafsson <[email protected]>
0 siblings, 1 reply; 9+ messages in thread
From: David Fetter @ 2021-09-15 06:06 UTC (permalink / raw)
To: Daniel Gustafsson <[email protected]>; +Cc: Michael Paquier <[email protected]>; Aleksander Alekseev <[email protected]>; pgsql-hackers
On Fri, Sep 03, 2021 at 08:27:55PM +0200, Daniel Gustafsson wrote:
> > On 19 May 2021, at 09:53, Michael Paquier <[email protected]> wrote:
> >
> > On Tue, Apr 27, 2021 at 12:58:52PM +0300, Aleksander Alekseev wrote:
> >> I've noticed there is no tab completion for ALTER TABLE xxx ADD. Here
> >> is an alternative version of the patch that fixes this as well. Not
> >> sure if this should be in the same commit though.
> >
> > - /* If we have ALTER TABLE <sth> DROP, provide COLUMN or CONSTRAINT */
> > - else if (Matches("ALTER", "TABLE", MatchAny, "DROP"))
> > + /* If we have ALTER TABLE <sth> ADD|DROP, provide COLUMN or CONSTRAINT */
> > + else if (Matches("ALTER", "TABLE", MatchAny, "ADD|DROP"))
> > Seems to me that the behavior to not complete with COLUMN or
> > CONSTRAINT for ADD is intentional, as it is possible to specify a
> > constraint or column name without the object type first. This
> > introduces a inconsistent behavior with what we do for columns with
> > ADD, for one. So a more consistent approach would be to list columns,
> > constraints, COLUMN and CONSTRAINT in the list of options available
> > after ADD.
> >
> > + else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
> > + {
> > + completion_info_charp = prev3_wd;
> > + COMPLETE_WITH_QUERY(Query_for_nonvalid_constraint_of_table);
> > + }
> > Specifying valid constraints is an authorized grammar, so it does not
> > seem that bad to keep things as they are, either. I would leave that
> > alone.
>
> This has stalled being marked Waiting on Author since May, and reading the
> above it sounds like marking it Returned with Feedback is the logical next step
> (patch also no longer applies).
Please find attached the next revision :)
Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
@ 2021-09-24 12:35 Aleksander Alekseev <[email protected]>
parent: David Fetter <[email protected]>
0 siblings, 1 reply; 9+ messages in thread
From: Aleksander Alekseev @ 2021-09-24 12:35 UTC (permalink / raw)
To: pgsql-hackers; +Cc: David Fetter <[email protected]>
Hi David,
> Please find attached the next revision :)
The patch didn't apply and couldn't pass cfbot [1]. The (hopefully)
corrected patch is attached. Other than that it looks OK to me but let's
see what cfbot will tell.
[1]: http://cfbot.cputube.org/patch_34_3113.log
--
Best regards,
Aleksander Alekseev
Attachments:
[application/octet-stream] v5-0001-psql-Fix-tab-completion-for-ALTER-TABLE.patch (1.9K, ../../CAJ7c6TNjJWRat2BYPUS=wpCh40+984zmu0=DAfNhjnTnc8HfKg@mail.gmail.com/3-v5-0001-psql-Fix-tab-completion-for-ALTER-TABLE.patch)
download | inline diff:
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 5cd5838668..b55166aa64 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -788,6 +788,15 @@ Query_for_index_of_table \
" and pg_catalog.quote_ident(c1.relname)='%s'"\
" and pg_catalog.pg_table_is_visible(c1.oid)"
+/* the silly-looking length condition is just to eat up the current word */
+#define Query_for_constraint_of_table_not_validated \
+"SELECT pg_catalog.quote_ident(conname) "\
+" FROM pg_catalog.pg_class c1, pg_catalog.pg_constraint con "\
+" WHERE c1.oid=conrelid and (%d = pg_catalog.length('%s'))"\
+" and pg_catalog.quote_ident(c1.relname)='%s'"\
+" and pg_catalog.pg_table_is_visible(c1.oid)" \
+" and NOT con.convalidated"
+
#define Query_for_all_table_constraints \
"SELECT pg_catalog.quote_ident(conname) "\
" FROM pg_catalog.pg_constraint c "\
@@ -2145,14 +2154,22 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_ATTR(prev3_wd, "");
/*
- * If we have ALTER TABLE <sth> ALTER|DROP|RENAME|VALIDATE CONSTRAINT,
+ * If we have ALTER TABLE <sth> ALTER|DROP|RENAME CONSTRAINT,
* provide list of constraints
*/
- else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME|VALIDATE", "CONSTRAINT"))
+ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT"))
{
completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_constraint_of_table);
}
+ /*
+ * ALTER TABLE <sth> VALIDATE CONSTRAINT <non-validated constraint>
+ */
+ else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT"))
+ {
+ completion_info_charp = prev3_wd;
+ COMPLETE_WITH_QUERY(Query_for_constraint_of_table_not_validated);
+ }
/* ALTER TABLE ALTER [COLUMN] <foo> */
else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny) ||
Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny))
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
@ 2021-09-24 13:51 Aleksander Alekseev <[email protected]>
parent: Aleksander Alekseev <[email protected]>
0 siblings, 0 replies; 9+ messages in thread
From: Aleksander Alekseev @ 2021-09-24 13:51 UTC (permalink / raw)
To: [email protected]; +Cc: David Fetter <[email protected]>
The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: tested, passed
The cfbot seems to be happy with the updated patch.
The new status of this patch is: Ready for Committer
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2021-09-24 13:51 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 00:24 Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ... David Fetter <[email protected]>
2021-04-27 09:33 ` Aleksander Alekseev <[email protected]>
2021-04-27 09:58 ` Aleksander Alekseev <[email protected]>
2021-05-19 07:53 ` Michael Paquier <[email protected]>
2021-09-03 18:27 ` Daniel Gustafsson <[email protected]>
2021-09-15 06:06 ` David Fetter <[email protected]>
2021-09-24 12:35 ` Aleksander Alekseev <[email protected]>
2021-09-24 13:51 ` Aleksander Alekseev <[email protected]>
2021-04-28 02:53 ` David Fetter <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox