Re: Pass ParseState as down to utility functions.

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: jian he <jian.universality@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Kirill Reshke <reshkekirill@gmail.com>, Alvaro Herrera <alvherre@alvh.no-ip.org>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-12-16T06:15:27Z
Lists: pgsql-hackers
On Thu, Dec 12, 2024 at 12:38:06PM +0800, jian he wrote:
> I am using DefineDomain(ParseState *pstate, CreateDomainStmt *stmt) for now.
> we can also pass querystring or another struct.

All the changes in the alternate outputs for collate are always tricky
to track.  As far as I can see, you've not missed a spot.  So applied
this one.

> 0002:
> passing AlterTableUtilityContext for some ALTER TABLE subroutine.
> add parser_errposition to some existing `ereport(ERROR` places.
> -------------------
> you mentioned ALTER DOMAIN, I have further simplified it at
> https://postgr.es/m/CACJufxG0N_WLfk-NC_k5w6vv26qLvXupbHvnkKtc2npftJQicQ@mail.gmail.com

-        likeType = typenameType(NULL, defGetTypeName(likeTypeEl), NULL);
+        likeType = typenameType(pstate, defGetTypeName(likeTypeEl), NULL);

The only test impacted by this change is the CREATE TYPE (LIKE) in
float8.  It seems like this should be separated as a change of its own
as it impacts its own command.

For the rest, we're just manipulating ATExecAddOf(),
ATPrepAlterColumnType() and ATExecAlterColumnType().  FWIW, I'm
feeling annoyed with these new make_parsestate() calls, also knowing
that we do it twice for the prep and exec parts of AlterColumnType.
Perhaps that's fine at the end, that's just an increase of calls to
make_parsestate(), still...

> like this command will fail, so we don't need to change
> create_domain.sgml synopsis section?

Yep, right.  I was getting the impression that it would be possible to
have these ones go through with the parser allowed them when I looked
at that last Thursday.  Will double-check to be sure.
--
Michael

Commits

  1. Print out error position for some ALTER TABLE ALTER COLUMN type

  2. Print out error position for some more DDLs

  3. Print out error position for CREATE DOMAIN

  4. Add some regression tests for missing DDL patterns

  5. Re-implement the ereport() macro using __VA_ARGS__.