Re: append fields for *where...*

From: Guillaume LELARGE <gleu(at)wanadoo(dot)fr>
To: Johnny C <juandelacruz(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: append fields for *where...*
Date: 2005-02-11 08:24:07
Message-ID: 420C6BA7.20809@wanadoo.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Johnny C wrote:
> I have the following tables:
>
> TABLE A
> month | year | item | num
> 1 2005 myitem 003
>
> TABLE B
> num | date | descr
> 003 02-01-2005 blahblah
> 003 01-01-2005 toratora
>
> I am trying to come up with something like:
> select date,item,descr from TABLEA a
> LEFT OUTER JOIN TABLEB b ON b.num=a.num
> WHERE date=month-01-year;
>
> How can you make month (append) - 01 - (append) year? and
> pass that as a condition to the field date? Is this possible?
>

This works for me :
WHERE (month||'-01-'||year)::timestamp=date;

Here is my session :
galette=# create table a (month int4, year int4, item varchar(255), num
int4);
CREATE TABLE
galette=# insert into a values (1,2005,'myitem',3);
INSERT 17296 1
galette=# create table b (num int4, date timestamp, descr varchar(255));
CREATE TABLE
galette=# insert into b values (3,'02-01-2005','blahblah');
INSERT 17299 1
galette=# insert into b values (3,'01-01-2005','toratora');
INSERT 17300 1
galette=# select date,item,descr from a
LEFT OUTER JOIN b ON b.num=a.num
WHERE (month||'-01-'||year)::timestamp=date;
date | item | descr
---------------------+--------+----------
2005-01-01 00:00:00 | myitem | toratora
(1 ligne)

--
Guillaume.
<!-- http://abs.traduc.org/
http://lfs.traduc.org/
http://traduc.postgresqlfr.org/ -->

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2005-02-11 09:22:08 Re: postgres 8 data directory other then default?
Previous Message Bruno Wolff III 2005-02-10 23:12:50 Re: append fields for *where...*