SQL questiom

Поиск
Список
Период
Сортировка
Искать

SQL questiom

От:
hamann.w@t-online.de
Дата:


Hi,

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('<>')

Kind regards
Wolfgang Hamann



Re: SQL questiom

От:
Thomas Boussekey <thomas.boussekey@gmail.com>
Дата:


Le ven. 21 janv. 2022 à 11:14, <hamann.w@t-online.de> a écrit :


Hi,

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>>')

Kind regards
Wolfgang Hamann



Hello Wolfgang,

You can use a FUNCTION to perform this operation

HTH,
Thomas

Re: SQL questiom

От:
Jacob Bunk Nielsen <jacob@bunk.cc>
Дата:
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



FAQ