X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D3C8F8BA16A for ; Fri, 11 Feb 2005 08:24:26 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57243-05 for ; Fri, 11 Feb 2005 08:24:11 +0000 (GMT) Received: from smtp8.wanadoo.fr (smtp8.wanadoo.fr [193.252.22.23]) by svr1.postgresql.org (Postfix) with ESMTP id 555B78BA15F for ; Fri, 11 Feb 2005 08:24:11 +0000 (GMT) Received: from me-wanadoo.net (unknown [127.0.0.1]) by mwinf0809.wanadoo.fr (SMTP Server) with ESMTP id 397651C001F4; Fri, 11 Feb 2005 09:24:10 +0100 (CET) Received: from [192.168.10.4] (ASte-Genev-Bois-153-1-26-25.w83-112.abo.wanadoo.fr [83.112.206.25]) by mwinf0809.wanadoo.fr (SMTP Server) with ESMTP id D5AF51C001D6; Fri, 11 Feb 2005 09:24:09 +0100 (CET) X-ME-UUID: 20050211082409875.D5AF51C001D6@mwinf0809.wanadoo.fr Message-ID: <420C6BA7.20809@wanadoo.fr> Date: Fri, 11 Feb 2005 09:24:07 +0100 From: Guillaume LELARGE User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Johnny C Cc: pgsql-sql@postgresql.org Subject: Re: append fields for *where...* References: <2bffcc33050210144524608491@mail.gmail.com> In-Reply-To: <2bffcc33050210144524608491@mail.gmail.com> X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigBADF2E0904FA9AFB5FC7AF91" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.831 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS X-Spam-Level: * X-Archive-Number: 200502/132 X-Sequence-Number: 20243 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigBADF2E0904FA9AFB5FC7AF91 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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. --------------enigBADF2E0904FA9AFB5FC7AF91 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCDGuqYmO3DB+cCkERAjNzAKDPuMsuhM+ZkrplEXp9q3rAI5nq1ACg47o8 KnKf9SdErCJuagCeUKRRGI0= =rLAt -----END PGP SIGNATURE----- --------------enigBADF2E0904FA9AFB5FC7AF91--