Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL interval error

Tags:

sql

postgresql

I run a query like this:

SELECT (SELECT expire_date FROM "License" WHERE license_id = 10)
      - interval '1 mon 133 days 22:19:49.191748'

And everything is well.
But when I try this:

SELECT (SELECT expire_date FROM "License" WHERE license_id = 10)
      - interval ((SELECT expire_date-now() FROM "License" WHERE license_id = 10)
                 + interval '1 months')

I get an error:

ERROR:  syntax error at or near "("
LINE 1: ...FROM "License" WHERE license_id = 10) - interval ((SELECT ex...
                                                             ^

Please help, thanks.

like image 615
Ahmad Avatar asked Jun 30 '26 09:06

Ahmad


1 Answers

My understanding is that Postgres allows the type 'string' syntax for specifying the type for simple literal constants. For anything else you have to use ...::type or CAST ( ... AS type ).

like image 66
Milen A. Radev Avatar answered Jul 02 '26 22:07

Milen A. Radev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!