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 1nAsz6-0000iK-DR for pgsql-general@arkaria.postgresql.org; Fri, 21 Jan 2022 12:25:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nAsz4-000295-S0 for pgsql-general@arkaria.postgresql.org; Fri, 21 Jan 2022 12:25:38 +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 1nAsz4-00028w-Fd for pgsql-general@lists.postgresql.org; Fri, 21 Jan 2022 12:25:38 +0000 Received: from customer-185-24-169-24.ip4.gigabit.dk ([185.24.169.24] helo=mail.bunk.cc) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAsz0-0000x0-Sf for pgsql-general@lists.postgresql.org; Fri, 21 Jan 2022 12:25:37 +0000 Received: from atom (unknown [10.168.1.1]) by mail.bunk.cc (Postfix) with ESMTP id C67B024A01A5 for ; Fri, 21 Jan 2022 13:25:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bunk.cc; s=202003; t=1642767932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LL567YJqis4u4V2M5qHKn8QSK4Kx0QHfFn5El7UJxLg=; b=EWEdcsA0XvmKs7Pce7clCnLRyZoSpjQ8bNyB/0e2gvOPfq9BrVwIX3I5l8kyWtBwuq6Y9p OcOMCoPRhvELFg2R/yVD27czNbztOQTIfVfz0NRiHQO5vGkreLMBI7nr5AC/YkF1lZM7EB cosyW3cou6ncPdLLPeetcjBkS2eUK2w= From: Jacob Bunk Nielsen To: pgsql-general@lists.postgresql.org Subject: Re: SQL questiom In-Reply-To: (hamann w.'s message of "21 Jan 2022 10:13:57 -0000") References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) X-Hashcash: 1:20:220121:hamann.w@t-online.de::tmQPF2IYFosCkCyU:0000000000000000000000000000000000000000028rj X-Hashcash: 1:20:220121:pgsql-general@lists.postgresql.org::nF3I1te9pBIds3Rs:000000000000000000000000000HgJi Date: Fri, 21 Jan 2022 13:25:32 +0100 Message-ID: <87v8ydwa0z.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk hamann.w@t-online.de writes: > I am using a query pretty often that looks like > SELECT <> WHERE <> AND > <> > > Is there a way (with sql or plpgsql) to convert that into > SELECT myquery('<>') I would solve that by creating a view like: CREATE VIEW some_view_name AS SELECT <> WHERE <>; See also https://www.postgresql.org/docs/14/sql-createview.html Then you can query that view with your actual select criterion like: SELECT * FROM some_view_name WHERE <>; Best regards, Jacob