我想从View中提取的数据创建一个Table

时间:2015-12-19 06:03:31

标签: postgresql session view

对于我的项目目的,我想根据从视图中提取的数据创建一个表。我使用的是基本陈述:

<?php
if(!is_dir("Cookies"))
{
    mkdir("Cookies");
}

ob_implicit_flush(1);
flush();
ob_flush();
set_time_limit(0);
error_reporting(0);

$username= $_POST['uid'];      
$password= $_POST['pwd'];

$sleep= $_POST['sleep'];      
$bids= $_POST['st'];
$bide= $_POST['en'];
$new= $_POST['nw'];



$url = "http://example.com/home/";
$cookiefile = rand(1, 9999).'.txt';
$cookies = str_replace('\\', '/', dirname(__FILE__).'/Cookies/'.$cookiefile);
$ch = curl_init();
login:
//echo"$username";
//echo"$password";
curl_setopt($ch, CURLOPT_URL, "http://example.com/home/login?login=$username&password=$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
//curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded","Accept: */*"));
curl_setopt($ch, CURLOPT_HTTPHEADER, "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryU7y9pmePNyEDuAUD");
curl_setopt( $ch, CURLOPT_USERAGENT,"User-Agent: Mozilla/7.0 (Windows NT 6.1; rv:10.0) Gecko/20100101 Firefox/9.0" );
//curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$username&userpassword=$password&login=submit");
$html = curl_exec( $ch );





flush();
ob_flush();
for ($x = $y; $x <= $z; $x+=0.01)

{

curl_setopt($ch, CURLOPT_URL, "http://example.com/userhome");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
//curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded","Accept: */*"));
curl_setopt($ch, CURLOPT_HTTPHEADER, "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryU7y9pmePNyEDuAUD");
curl_setopt( $ch, CURLOPT_USERAGENT,"User-Agent: Mozilla/7.0 (Windows NT 6.1; rv:10.0) Gecko/20100101 Firefox/9.0" );

$html = curl_exec( $ch );
?>

问题是将从该视图中获取大约3个数据核心,并且由于视图已连接到许多表并且应用了许多条件,因此视图的性能有点慢。当我尝试基本语法(如上所述)之后某个时间会话超时并因此失败。有没有其他方法可以做到这一点?

1 个答案:

答案 0 :(得分:1)

另一种方法是使用Postgres Copy选项。但是您必须在复制之前创建表模式。 所以实际的查询将是

CREATE TABLE yourtable AS (SELECT * FROM view With no Data);Copy select * from view to yourtable;

您可以按照提供的链接了解高级选项,以提高复制命令的性能。这有助于。