【问题标题】:INNER JOIN two temp table no respond in postgresql usibn pythonINNER JOIN 两个临时表在使用 python 的 postgresql 中没有响应
【发布时间】:2018-05-31 04:24:49
【问题描述】:

我已经运行了一个查询,该查询使用 python 在 postgresql 中内部连接两个临时表以查找不同的无线电参数。我还有 csv 文件,它增加了表名和列名。我使用 pandas 读取 csv 并多次查询 postgreqsql 并将结果插入到单元格调用 comparsion.cccheck_table_cell 中。

这是我的代码:

from ftplib import FTP
import os
import csv
import psycopg2
import time
from datetime import datetime, timedelta
import pandas as pd


today=datetime.strftime(datetime.now(), '%Y-%m-%d')
yesterday=datetime.strftime(datetime.now() - timedelta(2), '%Y- 
%m-%d')
i=0
abc=[]
conn = psycopg2.connect(
    host="xxx", 
    database="parameter",
    user="xxx",
    password="xxx",
    port="xxx"
)
abc =pd.read_csv(
    'xxxx/create_comp/164/cell_table.csv',
    header=None, index_col=False
)
table="insert into comparsion.cccheck_table_cell SELECT a.date as 
date,a.ne_name as ne_name,a.local_cell_id,'"+abc.iloc[i,1]+"' as 
parameter,a." + abc.iloc[i,1] + " as today_parameter,\
b." + abc.iloc[i,1] + " as yesterday_parameter FROM (select * from 
radio_parameter." + abc.iloc[i,0] + " \
where date='" + today + "')a INNER JOIN (select * from 
radio_parameter." + abc.iloc[i,0] + " where date='" + yesterday +
"')b ON a.ne_name = b.ne_name and a.local_cell_id=b.local_cell_id WHERE 
a." + abc.iloc[i,1] + " != b." + abc.iloc[i,1] + ";"
print(table)

cursor = conn.cursor()
cursor.execute(table)


cursor.close()
conn.commit()
conn.close()
print('done_1')

为了解决问题,我在执行一次时打印了查询。但是如果我内部连接两个临时表,我发现查询没有响应并且没有发现错误。

有没有人在执行没有响应但没有错误的查询时有这些经验?问题与服务器或数据库加载问题有关吗?(我的数据库大约 24GB)

【问题讨论】:

  • 查询是什么样的?

标签: python sql postgresql python-2.7


【解决方案1】:

关于你的 SQL 语句:

  • 首先,您是否有一个名为 radio_parameter 的架构,并且 您的查询有权访问该架构..?
  • 从变量abc.iloc[i,1] 派生的字面量前缀为a.b.。在这种情况下,请确保从中派生的列名 参数对于别名为 ab 的两个表都是正确的。

    从变量 abc.iloc[i,1] 派生的字面量没有前缀 位置可能会导致歧义。

  • SQL 中可以看到一些反斜杠 (\) 字符,你确定吗 这种用法是对的。

【讨论】:

  • 1.是的,我确定架构存在 2. a 和 b 是 alise 3. () 不影响查询。
  • @EdwinCheng 好的,你对歧义怎么看?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-24
  • 1970-01-01
  • 2015-05-16
  • 2021-11-19
  • 2021-08-07
  • 2016-03-31
相关资源
最近更新 更多