Skip to content

typecast date/time types to text in query #247

@ptrblgh

Description

@ptrblgh

I have a datatable and a text input filed. The expected behaviour would be to perform a search on postgresql table fields (including the timestamp ones, in this example: stamp).
I use loopback's where filter's like operator. But unfortunetly a cast would be necessary on the table's field (stamp::TEXT) to make it work.

the model's property:

"stamp": { "type": "String", "required": true, "length": null, "precision": null, "scale": null, "postgresql": { "columnName": "stamp", "dataType": "timestamp with time zone", "dataLength": null, "dataPrecision": null, "dataScale": null, "nullable": "NO" } },

the url:
http://localhost:3000/api/users?filter[where][stamp][like]=2017

the error:

length: 213 severity: ERROR code: 42883 hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. position: 246 file: parse_oper.c line: 766 routine: op_error error: operator does not exist: timestamp with time zone ~~ text at Connection.parseE (...node_modules\pg\lib\connection.js:569:11) at Connection.parseMessage (...node_modules\pg\lib\connection.js:396:17) at Socket. (..node_modules\pg\lib\connection.js:132:22) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at readableAddChunk (_stream_readable.js:176:18) at Socket.Readable.push (_stream_readable.js:134:10) at TCP.onread (net.js:548:20) 

the working query would be:
select stamp from du_user where stamp::text like '%2017%'

Right now i don't have any idea how to achieve a query like that with loopback/loopback-connector-postgresql.
Any suggestions/help would be appreciated.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions