Created
September 17, 2016 14:42
-
-
Save FernandoBasso/f945df3a3545b45e884aef849d37ada8 to your computer and use it in GitHub Desktop.
Use of INSERT and RETURNING in pgsql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO images ( | |
post_id | |
, extension | |
, position | |
, created_at) | |
(SELECT | |
'13' | |
, 'jpg' | |
, COALESCE(MAX(position), 0) + 1 | |
, CURRENT_TIMESTAMP | |
FROM images | |
WHERE post_id = '13') | |
RETURNING id, extension, position; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment