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

cannot insert array with PostgreSQL #119

Open
theDevelopper opened this issue Apr 8, 2021 · 4 comments
Open

cannot insert array with PostgreSQL #119

theDevelopper opened this issue Apr 8, 2021 · 4 comments
Labels

Comments

@theDevelopper
Copy link

Describe the bug
Using local-data-api 0.6.7 with PostgreSQL I get an error when trying to pass an array as parameters in AWS.RDSDataService function executeStatement using JavaScript.
Postgres supposts Arrays as data type and RDSDataService does as well. But using arrays with local-data-api seems to not be supported as I get the following error in the docker logs:

2021-04-08 11:59:22.921 [eventLoopGroupProxy-4-2] ERROR Application - Unhandled: POST - /Execute kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 1146: Encountered an unknown key 'arrayValue'

To Reproduce
Steps to reproduce the behavior:

  • Have setup using ProstgreSQL
  • Create a simple table with a column called col of type TEXT[]
    CREATE TABLE test ( col TEXT[] )
  • have simple node script trying to insert data
    const AWS = require('aws-sdk');
    const client = new AWS.RDSDataService({
       region: 'us-east-1',
       endpoint: 'http://127.0.0.1:8080',
    });
    
    (async function() {
       try {
     	  await client.executeStatement({
     		  resourceArn: 'arn:aws:rds:us-east-1:123456789012:cluster:dummy',
     		  secretArn: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:dummy',
     		  database: 'test',
     		  sql: 'INSERT INTO test (col) VALUES (:data)',
     		  parameters: [{
     			  name: 'data',
     			  value: {
     				  arrayValue: {
     					  stringValues: ['a', 'b']
     				  },
     			  },
     		  }]
     	  }).promise();
       }
       catch (e) {
     	  console.log(e);
       }
    })();

Expected behavior
a new entry in table test is created with the array ['a', 'b'] as value for column col.

Additional context
AWS documentation: https://docs.aws.amazon.com/rdsdataservice/latest/APIReference/API_ExecuteStatement.html

@koxudaxi koxudaxi added the enhancement New feature or request label Apr 8, 2021
@koxudaxi
Copy link
Owner

koxudaxi commented Apr 8, 2021

@theDevelopper
Thank you for creating this issue.
Yes, I have not implemented it yet.
I will add the feature.

@ormu5
Copy link

ormu5 commented Apr 16, 2021

FYI, for those Python/boto3 users out there, I do not believe boto3 yet supports this: boto/boto3#2272. So you will run the chance of this working correctly locally but breaking upon deploy.

I have taken to inserting arrays to Postgres as strings and explicitly casting them in the SQL statement.

@koxudaxi
Copy link
Owner

@theDevelopper
I ran your code.
But, I can get this error.

BadRequestException: Array parameters are not supported.
....

You use aws-sdk. But, aws-sdk doesn't support array parameters.
aws/aws-sdk#9

I think the feature is priority low.

@koxudaxi koxudaxi mentioned this issue Apr 22, 2021
@koxudaxi
Copy link
Owner

@theDevelopper
I confirm we can't insert array value into real data-api.
And Latest local-data-api returns the same error when you give arrayValue.
If you want to insert array value you should try this workaround.
https://github.com/koxudaxi/local-data-api#how-to-insert-array-data-into-postgresql

@koxudaxi koxudaxi added released and removed enhancement New feature or request labels Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants