pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Guillaume LELARGE <gleu@wanadoo.fr>
To: Johnny C <juandelacruz@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: append fields for *where...*
Date: Fri, 11 Feb 2005 09:24:07 +0100
Message-ID: <420C6BA7.20809@wanadoo.fr> (raw)
In-Reply-To: <2bffcc33050210144524608491@mail.gmail.com>
References: <2bffcc33050210144524608491@mail.gmail.com>

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/ -->

Attachments:

  signature.asc (application/pgp-signature, 188B) download

view thread (3+ messages)

Message-ID: <420C6BA7.20809@wanadoo.fr>
Permalink:  ../420C6BA7.20809@wanadoo.fr/
Also on:    postgresql.org/message-id/420C6BA7.20809@wanadoo.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gleu@wanadoo.fr, juandelacruz@gmail.com
  Subject: Re: append fields for *where...*
  In-Reply-To: <420C6BA7.20809@wanadoo.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox