Re: select function alias

From: Howard News <howardnews(at)selestial(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: select function alias
Date: 2016-11-30 14:03:28
Message-ID: 773069bd-8f31-c8a5-c9f5-bf7239dcab83@selestial.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 30/11/2016 13:42, Timoteo Blanco wrote:
> Howdy,
>
> I've a series of timestamp columns I'd like to alias in select
> statements. psql indicates my alias doesnt exist after
> I define it.
>
> Example -> select to_char(impressions_create_date,'yyyy-mm-dd') as ymd
> from impressionsdb where ymd like '2016-11%' ;
>
> psql always complains column ymd does not exist. I've inherited a
> series of tables with many timestamps and would like to
> shorten the select in queries without renaming any columns.
>
>
> postgresql 9.2 on Gentoo 4.4.26
>
> TIA, TRB
>

3 options:

1. Use the same to_char expression in the where clause
2. Use a sub-select to use the alias in the outer where clause
3. Use the original column in the where clause and use the timestamp
comparisson functions.

Howard.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karsten Hilbert 2016-11-30 14:06:56 Re: Verify Option with pg_dump
Previous Message Marcin Giedz 2016-11-30 14:00:16 PostgreSQl HA solution