2

I'm trying to insert data into redshift table using this SQL query:

insert into temp(JSON)({"name":"abc","lname":"xyz"});

but it does not work, I get an error:

Syntax error

Is there any way to insert json data into redshift using a query?

I want to insert a whole json object into query instead of passing key and values

2 Answers 2

3

You can use JSON_PARSE('serialized_json') - https://docs.aws.amazon.com/redshift/latest/dg/JSON_PARSE.html

The JSON column should be of the SUPER data type - https://docs.aws.amazon.com/redshift/latest/dg/r_SUPER_type.html

INSERT INTO temp
  (JSON)
VALUES
  (JSON_PARSE('{"name":"abc","lname":"xyz"}'));
Sign up to request clarification or add additional context in comments.

Comments

1

You may simply execute:

insert into temp values('{"name":"abc","lname":"xyz"}');

JSON as a datatype is not supported on Redshift - Amazon Redshift Documentation

2 Comments

Side-note. There are functions such as JSON_EXTRACT_ARRAY_ELEMENT_TEXT that can then use the JSON data stored in this way.
Update -> You can insert semi-structured data into redshift with the SUPER data type: docs.aws.amazon.com/redshift/latest/dg/r_SUPER_type.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.