简体   繁体   中英

In Postgres, is it possible to insert a constant combined with the result of SELECT?

For example suppose I have a table TRADES as follows

DATE, PRICE, ...

I wish to construct a table TRADING_DAYS as follows

MARKET, DATE

With sample data as follows

NYSE, 2011-03-03
NYSE, 2011-03-04
NYSE, 2011-03-05

Is it possible to write a query that extracts DATE from TRADES, combines it with the constant 'NYSE' and inserts into TRADING_DAYS?

INSERT INTO TRADING_DAYS 
SELECT 'NYSE', DATE
FROM TRADES

But I guess you want the distinct dates rather then duplicates?

INSERT INTO TRADING_DAYS 
SELECT DISTINCT 'NYSE', DATE
FROM TRADES
INSERT INTO TRADING_DAYS SELECT 'NYSE', DATE FROM TRADES

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM