0

Novice to postgresql here. On 8.3 (not my choice, can't do anything about it for near future).

I'm selecting some "time" text strings from a table and inserting them into a view:

create or replace view test as (
    select 
    case 
    when desc like '%opening%' then 'opening'
    when desc like '%closing%' then 'closing'
    else n/a
    end as time_type, 
    to_timestamp(time, 'MM/DD/YYYY HH:MI:SS AM') where time_type = 'closing' as closing_time,
    to_timestamp(time, 'MM/DD/YYYY HH:MI:SS AM') where time_type = 'opening' as opening_time
  from source_table);

I get the error:

ERROR:  syntax error at or near "as"
LINE 8: .../YYYY HH:MI:SS AM') where time_type = 'closing' as closing...

I've used this syntax before to create other views so I am confused. Is it because my where statements are incorrectly placed? But if I place them after the from, they will be applied universally, no, and that is not what I want.

1
  • You can only have a single WHERE clause in a SELECT statement. Commented May 31, 2013 at 20:52

2 Answers 2

1

Two expressions look like they should be case statements, e.g.:

case
when time_type = 'closing' then
  to_timestamp(time, 'MM/DD/YYYY HH:MI:SS AM')
else null
end as closing_time
Sign up to request clarification or add additional context in comments.

Comments

0

Convert the two projections beginning with to_timestamp to CASE statements as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.