Skip to content

Commit

Permalink
Add example of writing data back to Redshift using SQL API
Browse files Browse the repository at this point in the history
This updates the README to include an example of saving data back to Redshift while using the SQL language API.

Fixes #81.

Author: Josh Rosen <joshrosen@databricks.com>

Closes #110 from JoshRosen/document-saving-data-from-sql.
  • Loading branch information
JoshRosen committed Oct 22, 2015
1 parent 8cb40d1 commit 0d1b082
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,34 @@ df.write \

#### SQL

Reading data using SQL:

```sql
CREATE TABLE my_table
USING com.databricks.spark.redshift
OPTIONS (
dbtable 'my_table',
tempdir 's3n://path/for/temp/data',
url 'jdbc:redshift://redshifthost:5439/database?user=username&password=pass'
);
```

Writing data using SQL:

```sql
-- Create a new table, throwing an error if a table with the same name already exists:
CREATE TABLE my_table
USING com.databricks.spark.redshift
OPTIONS (dbtable 'my_table',
tempdir 's3n://my_bucket/tmp',
url 'jdbc:redshift://host:port/db?user=username&password=pass');
OPTIONS (
dbtable 'my_table',
tempdir 's3n://path/for/temp/data'
url 'jdbc:redshift://redshifthost:5439/database?user=username&password=pass'
)
AS SELECT * FROM tabletosave;
```

Note that the SQL API only supports the creation of new tables and not overwriting or appending; this corresponds to the default save mode of the other language APIs.

### Hadoop InputFormat

The library contains a Hadoop input format for Redshift tables unloaded with the ESCAPE option,
Expand Down Expand Up @@ -353,4 +373,4 @@ directly:

Version 0.4+ adds the DataSource API and JDBC, which is an entirely new API, so although this won't break
code using the InputFormat directly, you may wish to make use of the new functionality to avoid performing
<tt>UNLOAD</tt> queries manually.
<tt>UNLOAD</tt> queries manually.

0 comments on commit 0d1b082

Please sign in to comment.