![](/img/trans.png)
[英]Postgres - Insert timestamps in an INSERT INTO query while selecting values from tables?
[英]Insert from Dynamic Query in Postgres
使用我以前的文章中發布的參考解決方案,導致了另外一種情況。 嘗試插入我的目標表時(如下圖所示)。
-- Table: normalized_transaction
-- DROP TABLE normalized_transaction;
CREATE TABLE normalized_transaction
(
transaction_id uuid,
file_id uuid,
account_number character varying(40),
currency character varying(3),
trade_date date,
value_date date,
narration character varying(200),
amount numeric,
mesitis_account_number character varying(50),
tag character varying(255),
supporting_file_id uuid,
supporting_record_id uuid,
status integer DEFAULT 0,
source_type integer,
record_index integer DEFAULT 0
)
使用類似的查詢
INSERT INTO normalized_transaction(account_number, currency, trade_date)
select gen_Test('english');
fetch all in english;
結果出錯:
ERROR: INSERT has more target columns than expressions
LINE 2: ...NSERT INTO normalized_transaction(account_number, currency, ...
^
********** Error **********
ERROR: INSERT has more target columns than expressions
SQL state: 42601
Character: 53
select gen_Test('english');
fetch all in english;
將結果從表中插入的合適方法是什么。
您可以這樣嘗試:
INSERT INTO normalized_transaction(account_number, currency, trade_date)
SELECT foo.*
FROM gen_Test('english') as foo;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.