Postgres: Unable to use "::" cast syntax together with parameters
See original GitHub issueDescribe the bug I am unable to use PostgreSQL type cast “::” operator together with parameters. This works with AWS Data API.
To Reproduce Steps to reproduce the behavior:
- Run a query with a parameter and a type cast. E.g.
SELECT :some_param::VARCHAR
- See error
BadRequestException: ERROR: syntax error at or near ":"
Expected behavior Casts the parameter without an error.
Additional context If you use the other cast syntax, it works:
CAST ( expression AS target_type );
It also works without a parameter SELECT 'value'::VARCHAR
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Documentation: 15: CREATE CAST - PostgreSQL
Description. CREATE CAST defines a new cast. A cast specifies how to perform a conversion between two data types. For example, SELECT CAST(42...
Read more >PostgreSQL Cast Function 101: How to Convert One Data ...
Here, start by defining an expression that can be a table column, a constant, or an expression that produces a value. Next, select...
Read more >cast operator issue with JPA and Hibernate - Vlad Mihalcea
Learn how to use the PostgreSQL :: cast operator when writing a JPQL ... type cast operator conflicts with the JPA : named...
Read more >How do I cast a string to integer and have 0 in case of error in ...
SELECT myfield::integer FROM mytable WHERE myfield ~ E'^\\d+$';. Postgres shortcuts its conditionals, so you shouldn't get any non-integers hitting your :: ...
Read more >Connect to a Custom SQL Query - Tableau Help
Because databases have slightly different SQL syntax from each other, the custom SQL you use to connect to one database might be different...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for the update 🎉 ! I will give it a go later, I will close the issue for now.
It looks like you are not casting a parameter value but just a value literal.
:param::VARCHAR (and pass param=1) - throws error
vs
1::VARCHAR does not throw error