Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rYz1s-001KAc-Rm for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Feb 2024 01:53:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rYz1q-000zzh-JL for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Feb 2024 01:53:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rYz1p-000zzZ-Vq for pgsql-hackers@lists.postgresql.org; Sun, 11 Feb 2024 01:53:10 +0000 Received: from mout-u-204.mailbox.org ([80.241.59.204]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rYz1i-0068A8-RA for pgsql-hackers@lists.postgresql.org; Sun, 11 Feb 2024 01:53:08 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4TXVwT4whcz9sR0; Sun, 11 Feb 2024 02:52:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ewie.name; s=MBO0001; t=1707616377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Z+dDuzCk/Xg0fu3v0lya0BsCnqBQtv0nj0LZ+Bf+yc=; b=OrSTz+EBcolRtYLwuuWSSaZU9X38ce7zwwCzmFDIVguOvRBDeNIqFf0cDuDTkXXuXsJQf2 Ahy4cuZfBfrdxBHS1swqxI614X+yBjZbMCNbids2l6aYHIO0vXuKV1J6MKumK7F0w3YFRO QPNwTtRmFZAs37SDo3FgU0LB+VJa6Syel/4AwtS/4O/4/iByG9x7hryN2roLt1s1UOKzro OmFKHGf2XRW6J+yz0EQ74K69GpfAsmb03O9QTDufqoXPt+KSVkUPNNuFCc60STrzSscLhw xNVllut2fCoOrXpEAYRsj1YBNj9S4x9zDXf1ADbmHVCEvZrOUEqpo7Kpp5EEcQ== Date: Sun, 11 Feb 2024 02:52:56 +0100 (CET) From: Erik Wienhold To: jian he , "David E. Wheeler" Cc: Jim Jones , =?UTF-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= , pgsql-hackers@lists.postgresql.org, Pavel Stehule Message-ID: <1317430675.73641.1707616376477@office.mailbox.org> In-Reply-To: References: <87il33kmmn.fsf@wibble.ilmari.org> <505981B3-2572-41E0-896C-964DDF7048A9@justatheory.com> Subject: Re: Patch: Add parse_type Function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Let me comment on some issues since I wrote the very first version of parse_type() on which David's patch is based. > On 2024-02-01 01:00 +0100, jian he wrote: > > cosmetic issue. Looking around other error handling code, the format > should be something like: > ` > if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) > ereport(ERROR, > (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), > errmsg("function returning record called in" > "context that cannot accept type record"))); > ` +1 > `PG_FUNCTION_INFO_V1(parse_type);` > is unnecessary? > based on the error information: https://cirrus-ci.com/task/5899457502380032 > not sure why it only fails on windows. Yeah, it's not necessary for internal functions per [1]. It's a leftover from when this function was part of the pgtap extension. > +#define PARSE_TYPE_STRING_COLS 2 /* Returns two columns. */ > +#undef PARSE_TYPE_STRING_COLS > Are these necessary? > given that the comments already say return the OID and type modifier. Not sure what the convention here is but I found this in a couple of places, maybe even a tutorial on writing C functions. See `git grep '_COLS\s\+[1-9]'` for those instances. It's in line with my habit of avoiding magic constants. > + ( typid oid, > + typmod int4 ) > here `int4` should be `integer`? +1 > commit message: > `Also accounts for data typs that require the SQL grammar to be parsed:` > except the typo issue, this sentence is still hard for me to understand. Yes, the sentence is rather handwavy. What is meant here is that this function also resolves types whose typmod is determined by the SQL parser or some step after that. There are types whose typmod is whatever value is found inside the parenthesis, e.g. bit(13) has typmod 13. Our first idea before coming up with that function was to do some string manipulation and extract the typmod from inside the parenthesis. But we soon found out that other typmods don't translate one to one, e.g. varchar(13) has typmod 17. The interval type is also special because the typmod is some bitmask encoding of e.g. 'second(0)'. Hence the mention of the SQL grammar. > + > + Parses a string representing an SQL type declaration as used in a > + CREATE TABLE statement, optionally schema-qualified. > + Returns a record with two fields, typid and > + typmod, representing the OID and > modifier for the > + type. These correspond to the parameters to pass to the > + format_type > function. > + > > can be simplified: > + > + Parses a string representing an SQL data type, optionally > schema-qualified. > + Returns a record with two fields, typid and > + typmod, representing the OID and > modifier for the > + type. These correspond to the parameters to pass to the > + format_type > function. > + > (I don't have a strong opinion though) Sounds better. The CREATE TABLE reference is superfluous. [1] https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-C-V1-CALL-CONV -- Erik