Home > database >  POSTGRE query full
POSTGRE query full

Time:12-03

Everybody:
Slowly I found POSTGRE database query, two times more than essentially, this is how to return a responsibility?
I am using c #,
A new database:
String the connectionString="Server=localhost; Port=5432; The Username=postgres; Password=12345 ";
NpgsqlConnection conn=new NpgsqlConnection (the connectionString);
Conn. The Open ();
String SQL="CREATE DATABASE" + Name + "WITH OWNER=postgres ENCODING='UTF8' LC_COLLATE=" Chinese (Simplified) _China. 936 'LC_CTYPE="Chinese (Simplified) _China. 936' in TABLESPACE=pg_default CONNECTION LIMIT=1";
NpgsqlCommand objCommand=new NpgsqlCommand (SQL, conn);
ObjCommand. ExecuteNonQuery ();
Conn. Close ();
Conn. The Dispose ();
The new table:
String the connectionString="Server=localhost; Port=5432; The Username=postgres; Password=12345; The Database="+ DataBaseName +"; ";
NpgsqlConnection conn=new NpgsqlConnection (the connectionString);
Conn. The Open ();
String SQL="CREATE TABLE" + TableName +
"(time timestamp without time zone, TempratureA integer and PowerA integer, ACVoltageA integer, CoilVoltageA integer, DCCurrentA integer, HzA integer, DCVoltageA integer, StoveWaterFlowA integer, MachingWaterFlowA integer, CapVoltageA integer, INVCurrentA integer, TPreheatSA integer, TColdSA integer, RESA1 integer, RESA2 integer) WITH (OIDS=FALSE)";


NpgsqlCommand objCommand=new NpgsqlCommand (SQL, conn);
ObjCommand. ExecuteNonQuery ();

SQL="the CREATE INDEX x + TableName" + "ON" + TableName + "USING btree (time ASC crosstab LAST);";
ObjCommand=new NpgsqlCommand (SQL, conn);
ObjCommand. ExecuteNonQuery ();

SQL="ALTER TABLE" + TableName + "CLUSTER ON x + TableName" + "; ";
ObjCommand=new NpgsqlCommand (SQL, conn);
ObjCommand. ExecuteNonQuery ();

Conn. Close ();
Query:


String the connectionString="Server=localhost; Port=5432; The Username=postgres; Password=12345; The Database="+ DataBaseName +"; ";
NpgsqlConnection conn=new NpgsqlConnection (the connectionString);
Conn. The Open ();


DateTime StTime EdTime;
StTime=DateTime. Parse (StartTime);
EdTime=DateTime. Parse (EndTime);


String SQL="SELECT * FROM + TableName" + "where time & gt; '" + StTime + "' and time & lt; '" + EdTime + "; ";
NpgsqlCommand objCommand=new NpgsqlCommand (SQL, conn);

Da=new NpgsqlDataAdapter (objCommand);
Ds=new DataSet ();
Da. The Fill (ds, "ds");
ObjCommand. The Parameters. The Clear ();

ObjCommand. The Dispose ();
Ds. The Dispose ();

Conn. Close ();
Conn. The Dispose ();
Every time the query more than twenty thousand records, why is slow, is essentially a three times,
Masters can help have a look?
















  • Related