Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 45442AF82E9 for ; Mon, 9 Jan 2012 12:33:44 -0400 (AST) Received: from mail-gx0-f174.google.com ([209.85.161.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RkIAI-0000o5-8l for pgsql-sql@postgresql.org; Mon, 09 Jan 2012 16:33:43 +0000 Received: by ggdk6 with SMTP id k6so1635775ggd.19 for ; Mon, 09 Jan 2012 08:33:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; bh=o/Zckk6dQeaOfgS3AjKNYA4NWjtfVrPHnqofUTLXluk=; b=nlSU35EO+X7M/ViLsx46dkvt2htpFbr333PQTZMNN5v02k3GOciOtUM3zK5r+EqrpM 1X25mShlm/j0CatgNeSC4ICViDs3+1j/lwiruiUgT3mCHmyV82N3VpYS+H9tgv2JFPnY WumLHNyjVi8DdIWyO6knobu7d7Xs9L4R7dw7I= Received: by 10.182.111.7 with SMTP id ie7mr15360596obb.4.1326126808493; Mon, 09 Jan 2012 08:33:28 -0800 (PST) Received: from tucker.localnet (c-24-17-164-54.hsd1.wa.comcast.net. [24.17.164.54]) by mx.google.com with ESMTPS id l1sm76962287obv.1.2012.01.09.08.33.26 (version=SSLv3 cipher=OTHER); Mon, 09 Jan 2012 08:33:27 -0800 (PST) From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: compare table names Date: Mon, 9 Jan 2012 08:33:23 -0800 User-Agent: KMail/1.13.5 (Linux/2.6.32-37-generic; KDE/4.4.5; i686; ; ) Cc: Tony Capobianco References: <1326125538.1983.12.camel@tony1.localdomain> In-Reply-To: <1326125538.1983.12.camel@tony1.localdomain> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201201090833.24042.adrian.klaver@gmail.com> X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201201/31 X-Sequence-Number: 36202 On Monday, January 09, 2012 8:12:18 am Tony Capobianco wrote: > tablename > -------------------- > tmp_staging0109 > tmp_staging1229 > tmp_staging0108 > > How can I write this correctly? Had another idea. If you are looking for the highest numbered table below a certain number then maybe this: test(5432)aklaver=>\d name_test Table "public.name_test" Column | Type | Modifiers --------+-------------------+----------- fld_1 | character varying | test(5432)aklaver=>SELECT * from name_test ; fld_1 ----------------- tmp_staging0109 tmp_staging0108 tmp_staging1229 (3 rows) test(5432)aklaver=>select fld_1 from name_test where fld_1 like 'tmp_staging%' and fld_1< 'tmp_staging1230' order by fld_1 desc limit 1; fld_1 ----------------- tmp_staging1229 > > Thanks. > Tony -- Adrian Klaver adrian.klaver@gmail.com