Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsuccessful attempt to query in a date range using cd (<@) #1859

Closed
maca opened this issue May 30, 2021 · 3 comments
Closed

Unsuccessful attempt to query in a date range using cd (<@) #1859

maca opened this issue May 30, 2021 · 3 comments
Labels

Comments

@maca
Copy link

maca commented May 30, 2021

Environment

  • PostgreSQL version: 13.2
  • PostgREST version: 7.0.1
  • Operating system: Linux (5.12.6-arch1-1)

Description of issue

I am trying to replicate this query:

select * from api.songs where songs.released <@ '[2000-01-01, 2001-01-01]'::daterange;

But I cannot get PostgREST to cast the operand, I've tried the following:

GET http://localhost:3000/songs?released=cd.'[1994-02-01,2022-03-01]'
GET http://localhost:3000/songs?released=cd.'\[1994-02-01,2022-03-01\]'
GET http://localhost:3000/songs?released=cd.'[1994-02-01,2022-03-01]::daterange'

This is the response:

{
  "hint": null,
  "details": null,
  "code": "42804",
  "message": "could not determine polymorphic type anyrange because input has type unknown"
}
// GET http://localhost:3000/songs?released=cd.'[1994-02-01,2022-03-01]'
// HTTP/1.1 400 Bad Request
@steve-chavez
Copy link
Member

Hey @maca,

GET http://localhost:3000/songs?released=cd.'\[1994-02-01,2022-03-01\]'

Have you tried urlencoding the brackets? The request should be like:

GET http://localhost:3000/songs?released=cd.%5B1994-02-01,2022-03-01%5D

Also, what's the type of the released column? If it's a daterange then there should be no need to cast it.

@maca
Copy link
Author

maca commented Jun 1, 2021

Thank you @steve-chavez :)

The column is a date, this query gives me the results I want:

select * from api.songs where songs.released <@ '[2000-01-01, 2001-01-01]'::daterange;

Is there any way to cast the operand %5B1994-02-01,2022-03-01%5D of the cd operation to a ::daterange?

I've tried url encoding but the result is the same:

{
  "hint": null,
  "details": null,
  "code": "42804",
  "message": "could not determine polymorphic type anyrange because input has type unknown"
}
// GET http://localhost:3000/songs?released=cd.'[1994-02-01,2022-03-01]'
// HTTP/1.1 400 Bad Request

@steve-chavez
Copy link
Member

The column is a date
Is there any way to cast the operand %5B1994-02-01,2022-03-01%5D of the cd operation to a ::daterange?

Ah, I see why the error now. It's not possible to cast a filter, but you can create a computed column and do the casting inside, as suggested here.

Additionally, for this case I think you can just use the lte and gte operators.

-- should be equivalent to the <@ operation
select * from api.songs where songs.released >= '2000-01-01' and songs.released =< '2001-01-01';

-- then through the API
GET /songs?released=lte.2000-01-01&released=gte.2001-01-01

@PostgREST PostgREST locked and limited conversation to collaborators Jun 2, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Development

No branches or pull requests

3 participants