Postgresql build error

Asked

Viewed 56 times

2

Would anyone know if there is an error in the query below:

select name, cast(Extract(day from payday) as int) as 'day' from loan;

I cannot find the reason for a build error in the URI.

  • 1

    Swap 'day' for "day". The first is a string and the second is a delimited identifier (or quoted).

1 answer

3


I thought the problem would be in cast; went to create this fiddle and I realized the error message (42601: syntax error at or near "'day'") is related to alias, not to the extract.

Removing the quotes, the problem is solved:

select name, cast(Extract(day from payday) as int) as day from loan;
  • 2

    You can name with double quotes, and not with single quotes (apostrophe): "Day".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.