RE: substring .. - Mailing list pgsql-sql

From Francis Solomon
Subject RE: substring ..
Date
Msg-id NEBBIFFPELJMCJAODNPKMECECEAA.francis@stellison.co.uk
Whole thread Raw
In response to substring ..  (Jeff MacDonald <jeff@hub.org>)
List pgsql-sql
Hi Jeff,

'2000-12-14' is only 10 chars long.
You're asking for an 11-char long substring to match a 10-char ... not
going to happen!

You can see this better if you do something like this ...
select '@' || substr(datefoo,1,11) || '@' from table;

... and you'll get results like:

@2000-12-14 @

So, you could modify your query to do:

select foo from table where substr(datefoo, 1, 10) = '2000-12-14';

Alternatively, what's wrong with this approach?

select foo from table where date(datefoo) = '2000-12-14';

I think that might execute a little faster.

Hope this helps

Francis Solomon

> hi folks..
>
> i want to do this to a datetime field..
>
> select foo from table where substr(datefoo,1,11) = '2000-12-14';
>
> it returns no results yet..
>
> select substr(datefoo,1,11) does return some values that say
> 2000-12-14
>
> any clues ?
>
> Jeff MacDonald,



pgsql-sql by date:

Previous
From: "Emils Klotins"
Date:
Subject: group by: properly?
Next
From: Stephan Szabo
Date:
Subject: Re: substring ..