Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sOBLJ-00CqWH-QS for pgsql-general@arkaria.postgresql.org; Mon, 01 Jul 2024 07:20:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sOBLH-00G6xh-Og for pgsql-general@arkaria.postgresql.org; Mon, 01 Jul 2024 07:20:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sOBLH-00G6xX-9b for pgsql-general@lists.postgresql.org; Mon, 01 Jul 2024 07:20:51 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sOBLF-004RQ0-LF for pgsql-general@lists.postgresql.org; Mon, 01 Jul 2024 07:20:50 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-57cb9a370ddso3324564a12.1 for ; Mon, 01 Jul 2024 00:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peoplecall-com.20230601.gappssmtp.com; s=20230601; t=1719818448; x=1720423248; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Q7SYqcauXJWdqCwT11wEwzLPyXxwKojKy4x6VVfYnIY=; b=q9wpTHI2Aj4ccAxCzTIgWp7+D7RUHQ9cl0AeK6B6AzQrS54hxGvA9KguR9ebwCHEjm 5b5r0yZLOEkb9TJ7iff9zIYAw9Jy5OkeBKDWtGfvCp5e/YG6+zqs6zJLqg3JQ2EtRA3R xdOKIrPibY8BpUjYXQDPfhva0/WoB9SA84vx6Fq+RfP1d8+426H4mnRkoeFA0rOuf3By NK5MviZfjghSSyHMs+UL7vyYq0TUXyuxnbmRJe/FN2HI8gArjJM8AQhASwoL7Rd4mRaq y6BvnSLN9VXMLCg4DKd43GRZ5bvLcrOwJ3pBdc5jdsON1yfqk4Yv82lSIL8UsZ114peT 6KvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719818448; x=1720423248; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Q7SYqcauXJWdqCwT11wEwzLPyXxwKojKy4x6VVfYnIY=; b=AXEXajvZlebt9O1ftfvnxzu03PEGiQ4k2JSfcN+xnEoHW3PIrd5Uq9RkeB4Y6C+NBi aL/xtHRE2LrUq/cxVXxP+RAs6wyDAQ7uH5GtW5kpjbpqe+Ocq6XGd65i8PLDZyk/YzFr cCkeJRj0hoSeI5eGbCwQsr0jswZBJeLexy4UwJSp2Y4q2bnM0vPRQ2Cz8L2/s0oI3cbf pONihmxIzh1uUYq5C4AolwdgB7K9lLsAC3dBQwBBmaENrL7g0yfhAdvlw+ntXM+DLK01 wHBVHBozoMEEmUk24pR+xaTGfSd5kYLCZawvXSHOOmZdaRLnzTVo6gKDLMXbEjnFoaJd KBEA== X-Forwarded-Encrypted: i=1; AJvYcCV2JAp3Aa3tAZcrkp7nADmLAOt7057nmAr9CMleYLnbNmzBHOODglExAoxW7thIYC9PP9ZSSMqzjMxe12JYYtm1S2guNOFC5die3NcjBT16f9mn X-Gm-Message-State: AOJu0Yy1lC9az2smqg92RH+hybBhKYqUlCg8lnBwuzQjZy9U7LxLw7SN Y4A2Uv8+LsSWzx9t+bFiGjlWRh75Y6cyPxlW1p5o6FThheFEmbmqKs8wEgeUJ1I4knU+xtS+JXu 0ysUJsxOPwN39kl2Y5zHuMnvfPFr0Ft99zapIMPuGBWl58sPrlg== X-Google-Smtp-Source: AGHT+IH6FnEtADY3CR31mpQtvysnM8si33kESsMwwvLnq+mXJSXkfvFFH75bphuGol4/woksnSGa5nvYjKIyovpT4nE= X-Received: by 2002:a05:6402:4302:b0:57c:7f0d:304c with SMTP id 4fb4d7f45d1cf-5879ecea386mr3502530a12.1.1719818447807; Mon, 01 Jul 2024 00:20:47 -0700 (PDT) MIME-Version: 1.0 References: <2537942.1719787874@sss.pgh.pa.us> In-Reply-To: From: Francisco Olarte Date: Mon, 1 Jul 2024 09:20:11 +0200 Message-ID: Subject: Re: Passing a dynamic interval to generate_series() To: Igal Sapir Cc: Tom Lane , pgsql-general Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Igal: On Mon, 1 Jul 2024 at 01:17, Igal Sapir wrote: > I actually did test the expression that I posted, but it might be casting it twice. While your examples that you wrote show 1 month correctly: > SELECT (interval '1 ' || 'month'); > ?column? | > -------------+ > 00:00:01month| No, it does not, try it like this: s=> with a(x) as ( SELECT (interval '1 ' || 'month')) select x, pg_typeof(x) from a; x | pg_typeof ---------------+----------- 00:00:01month | text (1 row) And you'll understand what is happening. Cast to interval has higher priority then concatenation, so you are selecting a 1 second interval, casting it to text, '00:00:01', adding 'month' at end. This can also be noticed because month output would not use ':' and have spaces: s=> with a(x) as ( SELECT '001.00MONTHS'::interval) select x, pg_typeof(x) from a; x | pg_typeof -------+----------- 1 mon | interval (1 row) ( I used fractions, uppercase and no spaces on input to show how interval output normalizes ). Francisco Olarte.