Anatol
Anatol

Reputation: 2043

Postgres Combine Select and insert in one Query

pardon for this silly question, seems its to late to think clear.

How can I combine these two Queries in PostgreSQL to one. That "NewUserAge" gets insert into field age from query two?

SELECT max(age+1) as NewUserAge 
  FROM mytable;


INSERT INTO 
    mytable (age,name) 
VALUES
    (11,'Bert');

Thanks for your help,

tony

Upvotes: 0

Views: 1019

Answers (1)

John Woo
John Woo

Reputation: 263883

INSERT INTO mytable (age,name) 
SELECT  max(age) + 1, 'Bert'
FROM myTable

Upvotes: 2

Related Questions