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 1mH2P3-00061R-KX for pgsql-novice@arkaria.postgresql.org; Fri, 20 Aug 2021 11:09: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 1mH2OW-0007QA-Qw for pgsql-novice@arkaria.postgresql.org; Fri, 20 Aug 2021 11:09:04 +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 1mH1uj-00023q-Mz for pgsql-novice@lists.postgresql.org; Fri, 20 Aug 2021 10:38:17 +0000 Received: from esa05.ucs.mun.ca ([134.153.136.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mH1uf-0004Zv-69 for pgsql-novice@postgresql.org; Fri, 20 Aug 2021 10:38:14 +0000 IronPort-SDR: Mj8p0kNv3R0pCn33Dt7+zAuvwnHER5KoZrihmGlnxGPbfOUqDnJbGLRttwLWSdYIoA8m6+iWjv uD3tCbpynU8X1CfMzI7nQUSiAsCLSaHXII9a2jzTtyrHT+RIlKPTZxNadGUoLELxdXMiI1OamZ IJrejtR4KR1dqI1Yosmk9E5Sn69TMNdrneuBMpDC5pbtam5yNoIqGnnjUhR6RunjJddzPQesYo FcAO7IwwEY+lMfgsTk0adw6E8Mt2ExhOY8ZbxnkHOlBSX30IPWk4kzBCV1IDEwPavycxThFoGy 4lM= IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AEdHEHqmxf9uVm9o3M2QWcYNBzzjpDfIZ3D?= =?us-ascii?q?Abv31ZSRFFG/Fwz/re+cjzpiWE7Ar5OUtQ4exoV5PgfZqxz/RICMwqTNWftW?= =?us-ascii?q?rdyRCVxeNZjbcKqgeIc0bDH6xmpMRdmsNFZOEYeGIVsS+M2maF+rgbreVvu5?= =?us-ascii?q?rY4ts2h00dKz2CRZsQljtENg=3D=3D?= X-IronPort-AV: E=Sophos;i="5.84,337,1620700200"; d="scan'208";a="58600194" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from cpe00fc8db7a323-cm00fc8db7a320.cpe.net.cable.rogers.com (HELO pyrope.local) ([174.117.202.255]) by smtp05.ucs.mun.ca with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 08:08:09 -0330 User-agent: mu4e 1.5.6; emacs 27.2 From: Roger Mason To: pgsql-novice@postgresql.org Subject: plpgsql select into Date: Fri, 20 Aug 2021 08:08:07 -0230 Message-ID: MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, I want to take a multiline text column from one table, split it into rows and insert it into another table. Eventually this function will also need insert the 'id' field and a timestamp into the other table but for now I'm focused on dealing with the multiline text. I could code all this up in C++ but I'm doing it as a plpgsql function so that the function can be called from a trigger when the data are inserted into the database. So far an exercise in frustration. Here is may latest effort: CREATE OR REPLACE FUNCTION get_info (id text) RETURNS TABLE ( tabular_info text ) AS $function$ BEGIN RETURN query WITH a AS ( SELECT regexp_split_to_table(info_out, '\n') AS info FROM public.results WHERE public.results.jid = id ) SELECT * INTO tabular_info FROM a RETURN; END; $function$ LANGUAGE plpgsql; I execute the function: select get_info('1043_1'); ERROR: cannot open SELECT query as cursor CONTEXT: PL/pgSQL function get_info(text) line 3 at RETURN QUERY Perhaps what I'm trying to do is impossible, in which case it would be useful to know if a trigger can be set up to call out to an external command. I appreciate any help offered. Thanks, Roger