Skip to main content

redshift_to_postgres

Function redshift_to_postgres 

Source
pub fn redshift_to_postgres(connection_uri: impl ToString) -> Url
Expand description

Converts a Redshift IAM connection URI into a parsed PostgreSQL connection string with temporary credentials already embedded.

Parses connection_uri, performs the full IAM / SAML authentication flow (identical to read_sql), and returns the resulting postgres:// URL with the short-lived username and password substituted in.

This is useful when you need to hand a live connection string to a third-party library that speaks the PostgreSQL wire protocol directly (e.g. sqlx, diesel, psycopg2 via a subprocess) without going through connectorx.

§URI format

Accepts the same [jdbc:]redshift:iam://… format described in read_sql.

§Fallback behaviour

If the IAM / SAML exchange fails, the error is logged at the error level and the function falls back to returning the original URI with its scheme replaced by postgres. This allows callers to still attempt a direct connection using whatever credentials were present in the URI.

§Returns

A postgres://username:password@host:port/database connection string as an Url instance. The password is a short-lived STS session token and should not be cached beyond its expiry window.