8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLとPostgreSQLのSELECT句でのサブクエリ仕様相違

Last updated at Posted at 2015-05-28

MySQLだと以下の様にnum1と別名を付けたものを、同じSELECT句内で使用することが可能なのですが、PostgreSQLだと不可能でした。

SELECT 1 as num1, (select(num1 + 1)) as num2

これは、MySQLの制約のゆるさ故のようですが、これをPostgreSQLやろうとした場合、以下のようにすることで可能なようです。

WITH tbl AS (SELECT 1 as num1)
SELECT num1, num1 + 1 AS num2 from tbl
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?