dbTalk Databases Forums  

select substring('MTWTFSS', from (Extract (dow from current_date)),for 1)

comp.databases.postgresql comp.databases.postgresql


Discuss select substring('MTWTFSS', from (Extract (dow from current_date)),for 1) in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
danfan46
 
Posts: n/a

Default select substring('MTWTFSS', from (Extract (dow from current_date)),for 1) - 06-18-2010 , 03:52 PM






Hi!

I'm new to postgres and want to do something like

select substring('MTWTFSS', from (Extract (dow from current_date)), for 1)

I can't get the parser to accept anything I try.

am I way out?
/dg

Reply With Quote
  #2  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: select substring('MTWTFSS', from (Extract (dow from current_date)),for 1) - 06-18-2010 , 03:58 PM






danfan46 wrote on 18.06.2010 22:52:
Quote:
Hi!

I'm new to postgres and want to do something like

select substring('MTWTFSS', from (Extract (dow from current_date)), for 1)

I can't get the parser to accept anything I try.

What are you trying to do?

Reply With Quote
  #3  
Old   
danfan46
 
Posts: n/a

Default Re: select substring('MTWTFSS', from (Extract (dow from current_date)),for 1) - 06-18-2010 , 04:11 PM



Thomas Kellerer wrote:
Quote:

danfan46 wrote on 18.06.2010 22:52:
Hi!

I'm new to postgres and want to do something like

select substring('MTWTFSS', from (Extract (dow from current_date)),
for 1)

I can't get the parser to accept anything I try.


What are you trying to do?


In Db2 I would express it like this:
where substr(days, DAYOFWEEK_ISO(current_date),1) =
substr('MTWTFSS', DAYOFWEEK_ISO(current_date),1)
and substr(months,Month(current_date),1) = substr('JFMAMJJASOND',Month(current_date),1)

I want to find those rows that has an F in days in position 5 if current date is a friday
and a J in months position 6 if current month is June.
If not so the job is not eligible for scheduling.
This is a non normalized approach of course. :-)
/dg

Reply With Quote
  #4  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: select substring('MTWTFSS', from (Extract (dow from current_date)),for 1) - 06-18-2010 , 04:46 PM



danfan46 wrote on 18.06.2010 23:11:
Quote:
I want to find those rows that has an F in days in position 5 if current
date is a friday
and a J in months position 6 if current month is June.
If not so the job is not eligible for scheduling.
This is a non normalized approach of course. :-)
/dg
That makes things clearer

Quote:
select substring('MTWTFSS', from (Extract (dow from current_date)), for 1)
If you check the manual you'll see that the comma is incorrect to separate the parameters


So that should be:
select substring('MTWTFSS' from extract(dow from current_date) for 1)

Unfortunately that gives the following error:
function pg_catalog.substring(unknown, double precision, integer) does not exist

Now that tells us, that the result of the extract() function seems to be a double precision, but substring expects an integer.

So all you have to do is to cast this to an int:

select substring('MTWTFSS' from extract(dow from current_date)::integer for 1)

will return what you want.

Reply With Quote
  #5  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: select substring('MTWTFSS', from (Extract (dow fromcurrent_date)), for 1) - 06-18-2010 , 08:44 PM



On Fri, 18 Jun 2010 23:46:05 +0200, Thomas Kellerer wrote:

Quote:
select substring('MTWTFSS', from (Extract (dow from current_date)), for
1)

If you check the manual you'll see that the comma is incorrect to
separate the parameters
Actually, that can be done with the commas, too:

mgogala=# select substring('MTWTFSS',extract(dow from
current_date)::integer,1);
substring
-----------
F
(1 row)

Time: 0.315 ms
mgogala=#



--
http://mgogala.byethost5.com

Reply With Quote
  #6  
Old   
danfan46
 
Posts: n/a

Default Re: select substring('MTWTFSS', from (Extract (dow from current_date)),for 1) - 06-19-2010 , 02:25 AM



Mladen Gogala wrote:
Quote:
On Fri, 18 Jun 2010 23:46:05 +0200, Thomas Kellerer wrote:

select substring('MTWTFSS', from (Extract (dow from current_date)), for
1)
If you check the manual you'll see that the comma is incorrect to
separate the parameters

Actually, that can be done with the commas, too:

mgogala=# select substring('MTWTFSS',extract(dow from
current_date)::integer,1);
substring
-----------
F
(1 row)

Time: 0.315 ms
mgogala=#



Thanks a lot!
Quick response!
I prefer this second format.
/dg

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.