pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jacob Bunk Nielsen <jacob@bunk.cc>
To: pgsql-general@lists.postgresql.org
Subject: Re: SQL questiom
Date: Fri, 21 Jan 2022 13:25:32 +0100
Message-ID: <87v8ydwa0z.fsf@localhost> (raw)
In-Reply-To: <wolfgang-1220121111357.A0114263@linux-tuxedo>
References: <wolfgang-1220121111357.A0114263@linux-tuxedo>

hamann.w@t-online.de writes:

> I am using a query pretty often that looks like
> SELECT <<fixed columns from tables>> WHERE <<fixed join statements>> AND
> <<actual select criterion>>
>
> Is there a way (with sql or plpgsql)  to convert that into
> SELECT myquery('<<actual select criterion>>')

I would solve that by creating a view like:

CREATE VIEW some_view_name AS 
  SELECT <<fixed columns from tables>> WHERE <<fixed join statements>>;

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 <<actual select criterion>>;

Best regards,
Jacob






view thread (3+ messages)

Message-ID: <87v8ydwa0z.fsf@localhost>
Permalink:  ../87v8ydwa0z.fsf@localhost/
Also on:    postgresql.org/message-id/87v8ydwa0z.fsf@localhost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: jacob@bunk.cc
  Subject: Re: SQL questiom
  In-Reply-To: <87v8ydwa0z.fsf@localhost>
  References: <wolfgang-1220121111357.A0114263@linux-tuxedo> <87v8ydwa0z.fsf@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox