Skip to content

Instantly share code, notes, and snippets.

@ajjain

ajjain/book.sql

Last active Aug 29, 2015
Embed
What would you like to do?
PostgreSQL+MyBatis+Insert+Autogenerated ID
CREATE TABLE BOOK (
ID SERIAL PRIMARY KEY,
NAME VARCHAR (50) UNIQUE NOT NULL,
TITLE VARCHAR (100),
DESCRIPTION VARCHAR (200)
);
<mapper>
<select id="add_book" parameterType="map" resultType="map">
INSERT
INTO BOOK(NAME,TITLE,DESCRIPTION)
VALUES
(#{name},#{title},#{description})
RETURNING *;
</select>
<select id="add_book" parameterType="list" resultType="map">
INSERT
INTO BOOK(NAME,TITLE,DESCRIPTION)
VALUES
<foreach collection="list" item="item" index="index" open="" separator="," close="">
(#{item.name},#{item.title},#{item.description})
</foreach>
RETURNING *;
</select>
</mapper>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment