• postgres索引创建、 存储过程的创建以及在c#中的调用


    postgres创建索引参考

    http://www.cnblogs.com/stephen-liu74/archive/2012/05/09/2298182.html

       CREATE TABLE test1 (
            id integer,
            content varchar
        );
        CREATE INDEX test1_id_index ON test1 (id);    

    创建存储过程

    CREATE OR REPLACE FUNCTION update_sqs(lng "varchar", lat "varchar", gid "varchar")
    RETURNS void
    AS
    $BODY$
    DECLARE
    r RECORD;
    del bool;
    num int4 := 0;
    sql "varchar";
    BEGIN
    sql := 'UPDATE public.sqs_poi SET geocoding_lng = ' || lng || ', geocoding_lat = ' || lat || ' WHERE geoid=' || gid;
    execute sql;
    END;
    $BODY$
    LANGUAGE 'plpgsql' VOLATILE;

    下面是调用的代码

    AscMethod方法通过多线程调用

    for (int ii = 0; ii < 10; ii++)
    {
    Thread threadTmp = new Thread(new ParameterizedThreadStart(AscMethod));
    threadTmp.Start(ii);
    }

    public void AscMethod(object i)
    {

    double s1 = Convert.ToInt32(i)*500000;
    double s2 = Convert.ToInt32(i)*500000 + 500000;
    string strQuery = "SELECT pr, city, addr, geoid FROM public.sqs_poi WHERE geocoding_lng IS NULL AND geoid >= " + s1.ToString() + " AND geoid < " + s2.ToString() + ";";// LIMIT 500000 OFFSET 0
    NpgsqlConnection conn = new NpgsqlConnection("Server=" + Config.host + ";Port=5432;UserId=" + Config.user + ";Password=" + Config.password + ";Database=" + Config.database + ";Preload Reader=true;" + "CommandTimeout=0;ConnectionLifeTime=0;");
    // conn.Close();
    conn.Open();
    NpgsqlCommand SelectCmd = new NpgsqlCommand(strQuery, conn);
    NpgsqlDataReader StrReader = SelectCmd.ExecuteReader();
    //int line = 1;
    while (StrReader.Read())
    {
    string Address = StrReader["pr"].ToString() + StrReader["city"].ToString() + StrReader["addr"].ToString();
    string[] geoString = geocoing(Address);
    if (geoString == null)
    continue;
    try
    {
    //string updatesql = "UPDATE public.sqs_poi SET geocoding_lng = " + geoString[0] + ", geocoding_lat = " + geoString[1] + "WHERE geoid=" + StrReader["geoid"];
    //NpgsqlCommand cmdi = new NpgsqlCommand(updatesql, conn);
    NpgsqlCommand cmd = new NpgsqlCommand();
    cmd.Connection = conn;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "update_sqs";
    NpgsqlParameter p1 = new NpgsqlParameter("lng", DbType.String);
    NpgsqlParameter p2 = new NpgsqlParameter("lat", DbType.String);
    NpgsqlParameter p3 = new NpgsqlParameter("gid", DbType.String);
    p1.Value = geoString[0];
    p2.Value = geoString[1];
    p3.Value = StrReader["geoid"].ToString();
    cmd.Parameters.Add(p1);
    cmd.Parameters.Add(p2);
    cmd.Parameters.Add(p3);
    cmd.ExecuteNonQuery();
    }
    catch (Exception ei)
    {
    if (conn.State != ConnectionState.Open)//判断数据库是否断开
    {
    conn.Open();
    }
    continue;
    }
    // line++;
    }
    conn.Close();
    }

  • 相关阅读:
    Doc2Vec -- "tag '23943' not seen in training corpus/invalid" 错误
    一行代码书写的神奇
    MySQL8.0-Public Key Retrieval is not allowed
    Dubbo-admin-2.7上下(新旧)版本打包发布到Liunx服务器
    Git遇到SSL错误:fatal: unable to access 'https://***************': OpenSSL SSL_read: Connection was reset, errno 10054
    Google浏览器快捷键
    Windows快捷键
    IDEA快捷键
    LocalDateTime
    数组
  • 原文地址:https://www.cnblogs.com/lelehellow/p/5900622.html
Copyright © 2020-2023  润新知