pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Dale Seaburg <kg5lt@verizon.net>
Cc: pgsql-general@postgresql.org
Subject: Re: SQL syntax
Date: Fri, 02 Mar 2018 20:07:47 -0500
Message-ID: <15232.1520039267@sss.pgh.pa.us> (raw)
In-Reply-To: <8be3c025-ebf8-59f4-1ab8-22206947e078@aklaver.com>
References: <ff87d197-7438-5eb5-065d-f7c52c69b741@verizon.net>
	<8be3c025-ebf8-59f4-1ab8-22206947e078@aklaver.com>

Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 03/02/2018 04:36 PM, Dale Seaburg wrote:
>> To finish off the WHERE clause, I need to look at the first 2 letters, 
>> like "D:".  My question is how do I specify in the WHERE clause, to look 
>> at the first 2 characters in the Image_Filename column?  What is the 
>> correct SQL syntax for looking at just a portion of a column?

> SELECT "Image_Filename" FROM "Instruments" WHERE "ImageFilename" LIKE 'D:%';

Another way is to use the substring() function:

SELECT "Image_Filename" FROM "Instruments"
  WHERE substring("ImageFilename", 1, 2) = 'D:';

or if you want to use the SQL committee's COBOLish syntax:

SELECT "Image_Filename" FROM "Instruments"
  WHERE substring("ImageFilename" FROM 1 FOR 2) = 'D:';

Depending on what you're doing, either the pattern-match way or the
substring way might be more convenient.  The performance implications
are different too, though that won't matter to you unless you're dealing
with so much data that you want to create a specialized index to make
queries of this form faster.

			regards, tom lane




view thread (5+ messages)  latest in thread

Message-ID: <15232.1520039267@sss.pgh.pa.us>
Permalink:  ../15232.1520039267@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15232.1520039267@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, kg5lt@verizon.net
  Subject: Re: SQL syntax
  In-Reply-To: <15232.1520039267@sss.pgh.pa.us>
  References: <ff87d197-7438-5eb5-065d-f7c52c69b741@verizon.net> <8be3c025-ebf8-59f4-1ab8-22206947e078@aklaver.com> <15232.1520039267@sss.pgh.pa.us>

* 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