Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7592043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:48:22+00:00 2026-05-30T20:48:22+00:00

In PostgreSQL I want to concat the current_timestamp with an interval as follows: select

  • 0

In PostgreSQL I want to concat the current_timestamp with an interval as follows:

select current_timestamp + interval 2||' days'

But when I do, I get an error:

[Err] ERROR:  syntax error at or near "2"
LINE 1: select current_timestamp + interval 2||' days'

But if I do it like this, it works correctly:

select current_timestamp + interval '2 days'

Why does one work, but not the other?

With reference to the following page
http://www.postgresql.org/docs/8.0/static/functions-datetime.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:48:24+00:00Added an answer on May 30, 2026 at 8:48 pm

    Part of the problem is that the standard SQL expression for intervals quotes the number, but not the keywords. So you have to be careful.

    select current_date, current_date + interval '2' day;
    --
    2012-02-21   2012-02-23 00:00:00
    

    In PostgreSQL, quoting like ‘2 day’ and ‘2 days’ also works. So you might think that ‘2’ || ‘ days’ would be equivalent, but it’s not.

    select current_date, current_date + interval '2' || ' days';
    --
    2012-02-21   2012-02-21 00:00:02 days
    

    The solution, as A.H. said, is to cast the result string as an interval.

    You can also use a variable in place of 2. This generates a calendar for 2012.

    -- 0 to 365 is 366 days; 2012 is a leap year.
    select ('2012-01-01'::date + (n || ' days')::interval)::date calendar_date
    from generate_series(0, 365) n;
    

    I use that final cast to date, because date + interval returns a timestamp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to execute the following update query at PostgreSQL db but it does
I want to sort by rating DESC. It works with MySQL but on PostgreSQL.
I am using PostgreSQL Database. I want to get a column values from a
This PostgreSQL COPY command works: copy tablename from E'c:\\abc\\a.txt'; but I want the tablename
Question: I want to test an if statement in PostgreSQL: IF (SELECT COUNT(*) FROM
I want to create a WINDOW in PostgreSQL and get the row_number() from a
i want to connect to a postgresql database using the jdbc4 driver, but would
I want to make DB but I just know MySQL and PostgreSQL. Can you
I want to develop an application to connect to a PostgreSQL Database, I want
I have a Postgresql database on which I want to do a few cascading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.