Skip to content
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

RDS Api to_sql error when inserting to uuid type column #2960

Open
jethroguce opened this issue Sep 14, 2024 · 1 comment · May be fixed by #2961
Open

RDS Api to_sql error when inserting to uuid type column #2960

jethroguce opened this issue Sep 14, 2024 · 1 comment · May be fixed by #2961
Labels
bug Something isn't working needs-triage

Comments

@jethroguce
Copy link

Describe the bug

There's an issue with awswrangler when attempting to insert UUID values into a PostgreSQL table’s UUID column using the to_sql method with the AWS Data API.

:ERROR: column "id" is of type uuid but expression is of type text
:HINT: You will need to rewrite or cast the expression.

How to Reproduce

CREATE TABLE users (
    id UUID PRIMARY KEY,
    name VARCHAR(50)
);
import awswrangler as wr
import pandas as pd
import uuid

# Number of records to insert
num_records = 10

# Generate a list of random UUIDs for the 'id' column
id_list = [uuid.uuid4() for _ in range(num_records)]

# Sample DataFrame with random UUIDs for 'id' and names
df = pd.DataFrame({
    'id': id_list,  # Generated UUIDs
    'name': [f'User{i}' for i in range(1, num_records + 1)]  # Generate names as User1, User2, etc.
})

# AWS RDS connection parameters
db_cluster_arn = "your-cluster-arn"
db_credentials_secrets_store_arn = "your-secret-arn"
database = "your-database-name"
table_name = "users"

conn =  wr.data_api.rds.connect(
                resource_arn= db_cluster_arn,
                database= database,
                secret_arn= db_credentials_secrets_store_arn,
            )

# Attempt to insert data into a PostgreSQL table with a UUID column using awswrangler
try:
    wr.data_api.rds.to_sql(
        df=df,
        conn=conn,
        table=table_name,
        database=database,
        use_column_names=True,
        mode="append",
        sql_mode="ansi",
        index=False
    )
except Exception as e:
    print("An error occurred:", e)

Expected behavior

No response

Your project

No response

Screenshots

No response

OS

Mac

Python version

3.11.6

AWS SDK for pandas version

3.9.1

Additional context

No response

@jethroguce jethroguce added the bug Something isn't working label Sep 14, 2024
@jethroguce jethroguce linked a pull request Sep 14, 2024 that will close this issue
@jethroguce
Copy link
Author

@jaidisido can you take a look at this, I have already created a PR request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant