rahul
rahul

Reputation: 930

Insert a json in redShift using query

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

Upvotes: 2

Views: 3615

Answers (2)

K_at_play
K_at_play

Reputation: 41

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"}'));

Upvotes: 3

Yusuf Hassan
Yusuf Hassan

Reputation: 2013

You may simply execute:

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

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

Upvotes: 1

Related Questions