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.96) (envelope-from ) id 1w2bax-000R99-39 for pgsql-general@arkaria.postgresql.org; Tue, 17 Mar 2026 21:04:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w2baw-005GCT-2x for pgsql-general@arkaria.postgresql.org; Tue, 17 Mar 2026 21:04:54 +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.96) (envelope-from ) id 1w2baw-005GCK-1v for pgsql-general@lists.postgresql.org; Tue, 17 Mar 2026 21:04:54 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w2bat-00000000Fb5-1gf5 for pgsql-general@postgresql.org; Tue, 17 Mar 2026 21:04:53 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 62HL4opx566246; Tue, 17 Mar 2026 17:04:50 -0400 From: Tom Lane To: Adrian Klaver cc: Marcos Pegoraro , pgsql-general Subject: Re: Trying to understand pg_get_expr() In-reply-to: <5179b412-2eaa-4c96-89f3-53c2fb10dd31@aklaver.com> References: <114fe468-204a-43a9-8edc-26ffd6d598a4@aklaver.com> <5179b412-2eaa-4c96-89f3-53c2fb10dd31@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Tue, 17 Mar 2026 13:36:34 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <566244.1773781490.1@sss.pgh.pa.us> Date: Tue, 17 Mar 2026 17:04:50 -0400 Message-ID: <566245.1773781490@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Adrian Klaver writes: > adrelid | pg_typeof | pg_get_expr > --------------+-----------+--------------------------- > default_test | text | 'test'::character varying > default_test | text | 0 > Why is the second case not?: > '0'::integer PG's parser automatically attributes type integer to an unadorned integer literal, so no cast is necessary there, and pg_get_expr doesn't add one. But an unadorned string like 'test' does not have a determinate type (well, it has type "unknown", but that is an implementation artifact). We emit a cast construct to show what type the constant was resolved as. The bigger picture here is that pg_get_expr relies on the same code that is used for purposes like dumping views. We want the output to be such that subexpressions of a view will certainly be parsed as the same type they were interpreted as before. regards, tom lane