(如果我犯了一些错误,请纠正我)
我有两张桌子:
我创建了一个脚本,当它不在db中时删除图像,问题是: 我不知道如何检查同一请求中的活动内容和文章,因为此请求只是删除我的活动图像..
#!/bin/bash
db="intranet_carc_development"
user="benjamin"
echo "DELETING UNUSED FILES AND IMAGES..."
for f in public/uploads/files/*
do
if [[ -f "$f" ]]
then
f="$(basename "$f")"
psql $db $user -t -v "ON_ERROR_STOP=1" \
-c "select content from public.articles where content like '%$f%'" | grep . \
&& echo "exist" \
|| rm public/uploads/files/$f
fi
done
printf "DONE\n\n"
如果绑得像:
select content from public.articles, public.activities where content like '%$f%'"
但我有这个日志错误:
ERROR: column reference "content" is ambiguous
答案 0 :(得分:1)
您可以尝试类似
的内容WITH artcontent AS (
SELECT content
FROM public.articles
),
actcontent AS (
SELECT content
FROM public.activities
),
merge AS (
SELECT * FROM artcontent
UNION ALL
SELECT * FROM actcontent
)
SELECT *
FROM merge
UNION ALL语句将把你的两个结果artcontent(来自文章)和actcontent(来自活动)放在一起。
希望它会对你有所帮助!