question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres: Unable to use "::" cast syntax together with parameters

See original GitHub issue

Describe 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:

  1. Run a query with a parameter and a type cast. E.g. SELECT :some_param::VARCHAR
  2. 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
filipsukcommented, Mar 18, 2021

Thank you for the update 🎉 ! I will give it a go later, I will close the issue for now.

1reaction
filipsukcommented, Nov 21, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found