On Thu, 2020-08-27 at 12:55 -0300, Fontana Daniel C (Desartec S.R.L.) wrote:
> Hi, I am migrating a database from Sybase to PostgreSql 12.
>
> This select in sybase works for me, but with postgresql it accuses me
> "THERE IS NO COLUMN ls_numero"
>
> select '1234567890' as ls_number,
> substr (ls_number, 3, 3);
>
> Is it possible to get information from an alias in postgresql? how would the
> code be?
You have several options:
1. Repeat the literal:
select '1234567890' as ls_number,
substr ('1234567890', 3, 3);
2. Use a subquery:
select ls_number,
substr (ls_number, 3, 3)
FROM (SELECT '1234567890' AS ls_number) AS q;
3. Use a CTE:
WITH x AS (SELECT '1234567890' as ls_number)
SELECT ls_number,
substr (ls_number, 3, 3)
FROM x;
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com