| From: | Philip Alger <paalger0(at)gmail(dot)com> |
|---|---|
| To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
| Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: [PATCH] Add pretty formatting to pg_get_triggerdef |
| Date: | 2025-11-04 20:56:41 |
| Message-ID: | CAPXBC8+m3EcU2Nu6U+hEHFiS6RyvK1RNevBTuqX+EOxjs8nV5w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Chao,
+/*
> + * pg_get_triggerdef_compact
> + * Returns trigger definition in a compact, single-line
> format without
> + * schema qualification designed for the psql \d command.
> + */
> +Datum
> +pg_get_triggerdef_compact(PG_FUNCTION_ARGS)
> +{
> + Oid trigid = PG_GETARG_OID(0);
> + char *res;
> +
> + res = pg_get_triggerdef_worker(trigid, PRETTYFLAG_SCHEMA);
> ```
>
> I think this is a mis-use of PRETTYFLAG_SCHEMA that is for printing
> schema-qualified names but omitting schema.
>
Yes, this is to omit the schema because the functions is used to print out
the triggers when using \d in psql, The current practice isn't to print out
a schema for the table/view/etc.
2
> ```
> + if (prettyFlags & PRETTYFLAG_INDENT)
> + appendStringInfoString(&buf, "\n ");
> ```
>
> We should not hardcode 4 white-spaces, instead, we should use the const
> PRETTYINDENT_STD. Did you ever consider using appendContextKeyword()?
> Checking for an existing usage:
> ```
>
>
Thanks for pointing this out. I refactored the code using
appendContextKeyword() and added a few tests as well in v2 (attached).
> 3 Looks like you forgot to update pg_get_triggerdef(), when it calls
> pg_get_triggerdef_worker(tirgid, false), the second parameter “false”
> should be updated to an int flag.
>
I fixed this to set to 0. However, false is defined as 0 in stdbool.h
#define false 0
--
Best,
Phil Alger
EDB: https://www.enterprisedb.com
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Add-pretty-formatting-to-pg_get_triggerdef.patch | application/octet-stream | 20.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tomas Vondra | 2025-11-04 21:21:24 | Re: Adding basic NUMA awareness |
| Previous Message | Joel Jacobson | 2025-11-04 20:43:15 | Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue |