pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedSQL syntax
5+ messages / 5 participants
[nested] [flat]
* SQL syntax
@ 2018-03-03 00:36 Dale Seaburg <kg5lt@verizon.net>
2018-03-03 00:41 ` Re: SQL syntax Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 1 reply; 5+ messages in thread
From: Dale Seaburg @ 2018-03-03 00:36 UTC (permalink / raw)
To: pgsql-general
My mind is drawing a blank. Not sure where to go to find the answer.
Here is the statement in C#:
sSQL = "SELECT \"Image_Filename\" FROM \"Instruments\" WHERE ";
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?
I feel so dumb... This can't be that hard, but I am exhausted and
running out of ideas. I need someone to give me a boost! ;-)
Thanks,
Dale.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SQL syntax
2018-03-03 00:36 SQL syntax Dale Seaburg <kg5lt@verizon.net>
@ 2018-03-03 00:41 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-03-03 01:01 ` Re: SQL syntax Ken Tanzer <ken.tanzer@gmail.com>
2018-03-03 01:07 ` Re: SQL syntax Tom Lane <tgl@sss.pgh.pa.us>
2018-03-03 05:58 ` Re: SQL syntax Rob Sargent <robjsargent@gmail.com>
0 siblings, 3 replies; 5+ messages in thread
From: Adrian Klaver @ 2018-03-03 00:41 UTC (permalink / raw)
To: Dale Seaburg <kg5lt@verizon.net>; pgsql-general
On 03/02/2018 04:36 PM, Dale Seaburg wrote:
> My mind is drawing a blank. Not sure where to go to find the answer.
> Here is the statement in C#:
>
> sSQL = "SELECT \"Image_Filename\" FROM \"Instruments\" WHERE ";
>
> 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:%';
If you want case insensitive then ILIKE. For more info:
https://www.postgresql.org/docs/10/static/functions-matching.html#FUNCTIONS-LIKE
>
> I feel so dumb... This can't be that hard, but I am exhausted and
> running out of ideas. I need someone to give me a boost! ;-)
>
> Thanks,
> Dale.
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SQL syntax
2018-03-03 00:36 SQL syntax Dale Seaburg <kg5lt@verizon.net>
2018-03-03 00:41 ` Re: SQL syntax Adrian Klaver <adrian.klaver@aklaver.com>
@ 2018-03-03 01:01 ` Ken Tanzer <ken.tanzer@gmail.com>
2 siblings, 0 replies; 5+ messages in thread
From: Ken Tanzer @ 2018-03-03 01:01 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Dale Seaburg <kg5lt@verizon.net>; pgsql-general
On Fri, Mar 2, 2018 at 4:41 PM, Adrian Klaver <adrian.klaver@aklaver.com>
wrote:
> On 03/02/2018 04:36 PM, Dale Seaburg wrote:
>
>> My mind is drawing a blank. Not sure where to go to find the answer.
>> Here is the statement in C#:
>>
>> sSQL = "SELECT \"Image_Filename\" FROM \"Instruments\" WHERE ";
>>
>> 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:%';
>
> If you want case insensitive then ILIKE. For more info:
> https://www.postgresql.org/docs/10/static/functions-matching
> .html#FUNCTIONS-LIKE
>
>
It's not clear what kind of test you're trying to apply to those first two
characters. If you want to pull them out to use in an expression (e.g., if
you want to see if they are greater or less than something else), you can
use SUBSTRING or LEFT.
SELECT SUBSTRING('abc' FROM 1 FOR 2),LEFT('abc',2),LEFT('abc',2)<'aa'
AS is_less,LEFT('abc',2)>'aa' AS is_more;
substring | left | is_less | is_more
-----------+------+---------+---------
ab | ab | f | t
(1 row)
Cheers,
Ken
> --
>
AGENCY Software
A Free Software data system
By and for non-profits
*http://agency-software.org/ <http://agency-software.org/>*
*https://demo.agency-software.org/client
<https://demo.agency-software.org/client>*
ken.tanzer@agency-software.org
(253) 245-3801
Subscribe to the mailing list
<agency-general-request@lists.sourceforge.net?body=subscribe> to
learn more about AGENCY or
follow the discussion.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SQL syntax
2018-03-03 00:36 SQL syntax Dale Seaburg <kg5lt@verizon.net>
2018-03-03 00:41 ` Re: SQL syntax Adrian Klaver <adrian.klaver@aklaver.com>
@ 2018-03-03 01:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2018-03-03 01:07 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Dale Seaburg <kg5lt@verizon.net>; pgsql-general
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SQL syntax
2018-03-03 00:36 SQL syntax Dale Seaburg <kg5lt@verizon.net>
2018-03-03 00:41 ` Re: SQL syntax Adrian Klaver <adrian.klaver@aklaver.com>
@ 2018-03-03 05:58 ` Rob Sargent <robjsargent@gmail.com>
2 siblings, 0 replies; 5+ messages in thread
From: Rob Sargent @ 2018-03-03 05:58 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Dale Seaburg <kg5lt@verizon.net>; pgsql-general
> On Mar 2, 2018, at 5:41 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>
>> On 03/02/2018 04:36 PM, Dale Seaburg wrote:
>> My mind is drawing a blank. Not sure where to go to find the answer. Here is the statement in C#:
>> sSQL = "SELECT \"Image_Filename\" FROM \"Instruments\" WHERE ";
>> 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:%';
>
> If you want case insensitive then ILIKE. For more info:
> https://www.postgresql.org/docs/10/static/functions-matching.html#FUNCTIONS-LIKE
>
>> I feel so dumb... This can't be that hard, but I am exhausted and running out of ideas. I need someone to give me a boost! ;-)
>> Thanks,
>> Dale.
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
Use the tilda, Luke.
filename ~ ‘^D:’
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2018-03-03 05:58 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-03 00:36 SQL syntax Dale Seaburg <kg5lt@verizon.net>
2018-03-03 00:41 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-03-03 01:01 ` Ken Tanzer <ken.tanzer@gmail.com>
2018-03-03 01:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-03-03 05:58 ` Rob Sargent <robjsargent@gmail.com>
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