Skip site navigation (1) Skip section navigation (2)

RE: substring ..

From: "Francis Solomon" <francis(at)stellison(dot)co(dot)uk>
To: "Jeff MacDonald" <jeff(at)hub(dot)org>, "Pgsql-Sql(at)Postgresql(dot) Org" <pgsql-sql(at)postgresql(dot)org>
Subject: RE: substring ..
Date: 2000-12-19 20:14:00
Message-ID: NEBBIFFPELJMCJAODNPKMECECEAA.francis@stellison.co.uk (view raw or flat)
Thread:
Lists: 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,


In response to

pgsql-sql by date

Next:From: Robert B. EasterDate: 2000-12-19 21:31:42
Subject: Re: substring ..
Previous:From: Tulio OliveiraDate: 2000-12-19 20:13:09
Subject: Re: substring ..

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group