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 1p8Jz6-0003K0-KK for pgsql-general@arkaria.postgresql.org; Thu, 22 Dec 2022 11:43:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p8Jz5-0006Lv-Bp for pgsql-general@arkaria.postgresql.org; Thu, 22 Dec 2022 11:43:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p8Jz4-0006Ll-WD for pgsql-general@lists.postgresql.org; Thu, 22 Dec 2022 11:43:35 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p8Jz2-0003b9-5t for pgsql-general@lists.postgresql.org; Thu, 22 Dec 2022 11:43:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=zUUMYNXNRftOehxn4n4utzPNZlaEpJPBcrNj1tQ3/yI=; b=lolZqkTENnQM9BPU2vlUbpG9Dh dFCR1Yn1rbYKvaEHjPoBE0pJELD1YWvzQCgr5MjOXX72MPwJ5V9aiVwjKZCuqLg2mEusOXmhOE6lt wln3xcRIOTII6b1Xw1Tk4PH/upgb29z+8EC95Oo30gYFmDU9fZWdXxmK0iOwCIJfJbvA=; Received: from depesz by depesz.com with local (Exim 4.94.2) (envelope-from ) id 1p8Jz0-00Bq6E-Fo; Thu, 22 Dec 2022 12:43:30 +0100 Date: Thu, 22 Dec 2022 12:43:30 +0100 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: hamann.w@t-online.de Cc: pgsql-general@lists.postgresql.org Subject: Re: trouble writing plpgsql Message-ID: Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Dec 22, 2022 at 11:37:22AM -0000, hamann.w@t-online.de wrote: > I want to make a function to parsetext and return key-value pairs > create or replace function extractinfo (text) returns table (key char[1], val text) Please don't use char datatype: https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_char.28n.29 > language plpgsql as $$ > > I first tried > declare > xx record; > begin > .... > xx.key = ....; xx.val = ....; > return next xx: > This is not possible because xx needs to know its structure before the fields can be assiged to. > Could I declare xx as having these fields in the first place, do Ineedto create a type for key, val > first? select '...' as key, '...' as val into record; depesz