At the time of this writing Redshift does not support the PostgreSQL RETURNING fields
syntax nor JDBC Statement.RETURN_GENERATED_KEYS
. If you attempt something like:
SQL"""INSERT INTO ...""".executeInsert(long("id"))
you'll be rewarded with:
java.sql.SQLFeatureNotSupportedException: [Amazon][JDBC](10220) Driver not capable.
To get around this you need to wrap things inside a transaction and get the maximum ID value from the table - straight from 1998:
SQL"BEGIN;".execute()
SQL"""INSERT INTO table_x (date_created, name, source, meta)
VALUES (${dateCreated.toDate}, $name, $source, $meta);""".execute()
val result = SQL"""SELECT MAX(id) FROM table_x;""".executeQuery().single(long(1))
SQL"COMMIT;".execute()
result