From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | "Fontana Daniel C (Desartec S(dot)R(dot)L(dot))" <desartecsrl(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Postgres and alias |
Date: | 2020-08-28 11:40:43 |
Message-ID: | d84342ef8ebc5b283656b8a9452fb95c9f2bddf2.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | luis.roberto | 2020-08-28 11:59:08 | Re: Performance of "distinct with limit" |
Previous Message | Klaudie Willis | 2020-08-28 11:29:58 | Performance of "distinct with limit" |