Re: The PostgreSQL C Dialect

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Christophe Pettus <xof(at)thebuild(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: The PostgreSQL C Dialect
Date: 2026-07-01 14:44:49
Message-ID: CACJufxFkyibbUfR0fY+yzS+GcyyO-4aZ2TQ_Liu75sCi03Rawg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jun 23, 2026 at 3:39 AM Christophe Pettus <xof(at)thebuild(dot)com> wrote:
>
> When I was writing my first PostgreSQL extension, I was at sea on a lot of the conventions that make up the "PostgreSQL C Dialect." I've taken my notes, added some additional things that confused me, and put it up on the wiki for review:
>
> https://wiki.postgresql.org/wiki/The_PostgreSQL_C_Dialect
>

In many cases, we may need to add trailing commas to enum definitions.
See https://git.postgresql.org/cgit/postgresql.git/commit/?id=611806cd726fc92989ac918eac48fd8d684869c7

https://www.postgresql.org/docs/current/error-message-reporting.html
already mentioned that
```The extra parentheses were required before PostgreSQL version 12,
but are now optional.```.

Fewer parentheses are generally more readable, IMHO.
So https://wiki.postgresql.org/wiki/The_PostgreSQL_C_Dialect

ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));

can be replaced by

ereport(ERROR,
errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero"));

````
The compiler‑attribute wrappers: pg_attribute_noreturn(),
pg_attribute_printf(), pg_attribute_unused(), pg_noinline,
pg_nodiscard, and pg_unreachable() — portable spellings with fallbacks
where a compiler lacks the underlying feature.
````
pg_attribute_noreturn is replaced by something else, probabaly by
pg_noreturn (i am not so sure).

```
Validity helpers such as PointerIsValid() and OidIsValid().
```
PointerIsValid() is removed.

--
jian
https://www.enterprisedb.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-07-01 14:54:55 Re: postgres_fdw: fix cumulative stats after imported foreign-table stats
Previous Message Heikki Linnakangas 2026-07-01 14:43:50 Re: Adding REPACK [concurrently]