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 1puCXX-0000kl-Nw for pgsql-general@arkaria.postgresql.org; Wed, 03 May 2023 13:29:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1puCXW-0005Ad-M8 for pgsql-general@arkaria.postgresql.org; Wed, 03 May 2023 13:29:02 +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 1puCXW-0005AU-BZ for pgsql-general@lists.postgresql.org; Wed, 03 May 2023 13:29:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1puCXT-000JJl-SK for pgsql-general@lists.postgresql.org; Wed, 03 May 2023 13:29:01 +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 343DSt8K2955823; Wed, 3 May 2023 09:28:55 -0400 From: Tom Lane To: "J.A." cc: Erik Wienhold , pgsql-general@lists.postgresql.org Subject: Re: PL/pgSQL doesn't support variables in queries? In-reply-to: References: <658455455.1152531.1683117585087@office.mailbox.org> Comments: In-reply-to "J.A." message dated "Wed, 03 May 2023 22:51:25 +1000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2955821.1683120535.1@sss.pgh.pa.us> Date: Wed, 03 May 2023 09:28:55 -0400 Message-ID: <2955822.1683120535@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "J.A." writes: > I must admit, I did try doing something like you suggested Erik. I tried > things like: > DO $$ > DECLARE > v_application_id uuid; > BEGIN > SELECT application_id INTO v_application_id FROM applications > WHERE code = 'pg-test-cc'; > SELECT * FROM application_foo WHERE application_id = > v_application_id; > -- more SELECT * FROM child tables.... > END $$; > but that never worked, with warning: > ERROR: query has no destination for result data HINT: If you want to > discard the results of a SELECT, use PERFORM instead. CONTEXT: PL/pgSQL > function inline_code_block line 7 at SQL statement SQL state: 42601 Note that that is complaining about your second try, not your first. You need to put the result of the SELECT somewhere. INTO is fine if it's a single-row result. Otherwise, consider looping through the result with a FOR loop. Again, there are plenty of examples in the manual. regards, tom lane