要求:将行数附加到文件的尾端
SQL
COPY INTO @s3bucket/path/filename.txt
FROM(SELECT
a.acct_num,
a.state,
CASE WHEN b.tn IS NOT NULL THEN 'Y' ELSE 'N' END IND
FROM table_A a
LEFT OUTER JOIN table_B b ON a.tn = b.tn
);
预期的输出 TR|3
应该附加到文件的尾部
"1111"|"NEWYORK"|"N"
"2222"|"NEWJERSEY|"Y"
"333"|"TEXAS"|"N"
TR|3
编辑1:
使用@Iron DBA提到的COPY命令上载数据 并实现了Python函数更新尾行
答案 0 :(得分:1)
也许您可以使用UNION ALL将计数包括在最后一行:
copy into @deneme from
(
with st as (
select * from values
('1111','NEWYORK','N'),
('2222','NEWJERSEY','Y'),
('333','TEXAS','N') tmp(acct_num, state, ind ) )
select acct_num, state, ind from (
select *, 0 sorting_column from st
union all
select 'TR',count(*)::VARCHAR,null, 1 from st)
order by sorting_column
);
select $1, $2, $3 from @testing;
+------+-----------+----+
| $1 | $2 | $3 |
+------+-----------+----+
| 1111 | NEWYORK | N |
| 2222 | NEWJERSEY | Y |
| 333 | TEXAS | N |
| TR | 3 | |
+------+-----------+----+