Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ov18d-0007Ww-PP for pgsql-general@arkaria.postgresql.org; Tue, 15 Nov 2022 18:58:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ov18c-0003aJ-MC for pgsql-general@arkaria.postgresql.org; Tue, 15 Nov 2022 18:58:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ov18c-0003Za-Bn for pgsql-general@lists.postgresql.org; Tue, 15 Nov 2022 18:58:26 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ov18V-00029l-S8 for pgsql-general@lists.postgresql.org; Tue, 15 Nov 2022 18:58:25 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 12BD15C027E; Tue, 15 Nov 2022 13:58:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 15 Nov 2022 13:58:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1668538699; x= 1668625099; bh=rXlRXJFIOsOJJywzOJBjH1XwwMogNS6JlI9kbKyNKDE=; b=S O1fM5smnpiaj4zOUbxCaMV87pm9QYg+hhc4Ikbth9U2ac7Nrb7VI2vDiTYsDR9yk iYKEPtwDt+nFeP491A+CmPZ/JpisSmrJvbNIjqh9ojl6WzD7JaBmtIfA0Wxs4UuG p1u8sNUHt11HINB5JOUfmstJZSTzF1hcnzbb5F6ZrTXzeoRvKTDQftkqdqV/3r5C Lqt7MXdxst6Mev1vrxZvBT6zH9siyAoN7Tn5ybF2lZVbEEn1iynAkxCiB4qXKIDn JmM8ByVaLDTGqmcNlmIy5FuAZHmDYZ3vyfb3jT00Pv0nP9XHRHtUI3Q2TejNLEBe sq2bvHWYjfsNYEJccogGw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1668538699; x= 1668625099; bh=rXlRXJFIOsOJJywzOJBjH1XwwMogNS6JlI9kbKyNKDE=; b=G 8kegWHoVelt8W22DntXl2Xs3VPEV+oWiTUxAqIfA7+jilta+fI6a4KAj0v08I78g dosF6JzPOevGzFrgMfePQum4nXYnMTuKKL0xastuChTqIgPZpock3EnruG6d+7SV Vt7faCWG4C2w3fM2pvvrmFy6e/GdntAjEiEaewjRKoEMA7dW19tDATMKcyWdobG0 a65o5aW01PuijW2SaWgf0Ebk38m+C3g3DDWZbc3bkcOa175/ItPhGva9M2lqHpVT cIAIWp2KRmyL7q04JKPtq+paI9dQSD2zyhaggbfzaAL6XYdp51NdBvSIbpwimkLk c5KC7PTLaWwgznSbnhzdA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrgeeggdduudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvvehfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepgefhheehteelgfffkedukeelkeehffeiuddttdfg jeffudfggeefvdejjeefuedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Nov 2022 13:58:18 -0500 (EST) Subject: Re: Calling function from VFP changes character field to Memo To: Frank Cazabon , Tom Lane Cc: pgsql-general@lists.postgresql.org References: <1177304.1668537843@sss.pgh.pa.us> <7dc224a2-df53-de4a-42a6-a61502c71d95@gmail.com> From: Adrian Klaver Message-ID: Date: Tue, 15 Nov 2022 10:58:17 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <7dc224a2-df53-de4a-42a6-a61502c71d95@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/15/22 10:54 AM, Frank Cazabon wrote: > > On 15/11/2022 2:44 pm, Tom Lane wrote: >> Frank Cazabon writes: >>> If however I have a function defined like this >>> CREATE OR REPLACE FUNCTION public.testfunction( >>>       ) >>>       RETURNS TABLE >>>       ( >>>           Firstname character(30) >>>       ) >>>       LANGUAGE 'plpgsql' >>> AS $BODY$ >>> BEGIN >>>       RETURN QUERY SELECT p.cFirstName FROM patients p; >>> END; >>> $BODY$; >>> And I call: >>> SELECT * FROM public.testFunction(); >>> Then FirstName returns as a Memo field (similar to a Text field). >> This is mostly about whatever software stack you're using on the >> client side --- Memo is certainly not something Postgres knows about. >> >>> Any idea what I need to do to get it to return the character(30) type? >> There's no chance of getting back the "30" part with this structure, >> because function signatures do not carry length restrictions. >> What I expect is happening is that you get firstname as an >> unspecified-length "character" type, and something on the client >> side is deciding to cope with that by calling it "Memo" instead. >> >> You could perhaps work around that by defining a named composite >> type: >> >> create type testfunction_result as (firstname character(30), ...); >> >> create function testfunction() returns setof testfunction_result as ... >> >>             regards, tom lane > Thanks, so I could define the function like this - removed the (30): > > CREATE OR REPLACE FUNCTION public.testfunction( >      ) >      RETURNS TABLE >      ( >          Firstname character >      ) >      LANGUAGE 'plpgsql' No you don't want to do that: select 'test'::char; bpchar -------- t vs select 'test'::varchar; varchar --------- test Besides you missed the important part, after creating the type testfunction_result: create function testfunction() returns setof testfunction_result as ... > > I'll try the type definition and see if that helps. > > -- Adrian Klaver adrian.klaver@aklaver.com