Re: Postgres and alias

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: "Fontana Daniel C (Desartec S(dot)R(dot)L(dot))" <desartecsrl(at)gmail(dot)com>
Cc: Stelios Sfakianakis <sgsfak(at)gmail(dot)com>, Paul Förster <paul(dot)foerster(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Postgres and alias
Date: 2020-08-28 07:16:14
Message-ID: 8D3572D6-479D-4DF0-B3DC-F31AD4FC950B@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> On 28 Aug 2020, at 2:14, Fontana Daniel C (Desartec S.R.L.) <desartecsrl(at)gmail(dot)com> wrote:
>
> Perfect.
>
> now let's imagine that '1234567890' is a function f_art_get_price(id_code),
> which returns in a string like the following 'XXXZMMM1234567890123yyyy/mm/dd'
> where 1234567890123 is the price and yyyy/mm/dd the date it was last changed price.
> How would you do in this case to obtain these values ​​separately?
> without calling the function 2 times avoiding overloading the base?
>
> something like this
>
> select art.description,
> f_art_get_price_str( art.id ) as ls_price_and_date
> SUBSTRING( ls_price_and_date, 7, 13 )
> from articulos;

Let's assume art is supposed to be an alias for articulos.
Something like this?:

select art.description,
p.ls_price_and_date,
SUBSTRING( p.ls_price_and_date, 7, 13 )
from articulos art
cross join lateral f_art_get_price_str( art.id ) p(ls_price_and_date);

Alban Hertroys
--
There is always an exception to always.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stelios Sfakianakis 2020-08-28 07:16:42 Re: Postgres and alias
Previous Message Fontana Daniel C (Desartec S.R.L.) 2020-08-28 00:14:05 Postgres and alias