测试表

/*
Navicat Premium Data Transfer Source Server : localhost
Source Server Type : PostgreSQL
Source Server Version : 90401
Source Host : localhost
Source Database : mmc
Source Schema : public Target Server Type : PostgreSQL
Target Server Version : 90401
File Encoding : utf-8 Date: 08/15/2015 20:24:56 PM
*/ -- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS "public"."student";
CREATE TABLE "public"."student" (
"id" int4 NOT NULL DEFAULT nextval('student_id_seq'::regclass),
"name" varchar(255) NOT NULL DEFAULT ''::character varying COLLATE "default",
"age" int4 NOT NULL DEFAULT 0
)
WITH (OIDS=FALSE);
ALTER TABLE "public"."student" OWNER TO "mmc"; -- ----------------------------
-- Records of student
-- ----------------------------
BEGIN;
INSERT INTO "public"."student" VALUES ('', 'tom', '');
COMMIT; -- ----------------------------
-- Primary key structure for table student
-- ----------------------------
ALTER TABLE "public"."student" ADD PRIMARY KEY ("id") NOT DEFERRABLE INITIALLY IMMEDIATE;

直接贴代码

package main

import (
"fmt"
"github.com/go-xorm/xorm"
_ "github.com/lib/pq"
"reflect"
"unsafe"
) var engine *xorm.Engine func BytesToString(b []byte) string {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := reflect.StringHeader{bh.Data, bh.Len}
return *(*string)(unsafe.Pointer(&sh))
} func StringToBytes(s string) []byte {
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh := reflect.SliceHeader{sh.Data, sh.Len, }
return *(*[]byte)(unsafe.Pointer(&bh))
} func main() {
engine, _ = xorm.NewEngine("postgres", "user=mmc password=mmc dbname=mmc host=127.0.0.1 port=5432 sslmode=disable")
sql := "select * from student"
rowArray, _ := engine.Query(sql)
for _, row := range rowArray {
for colName, colValue := range row {
value := BytesToString(colValue)
fmt.Println(colName, value)
}
}
}

xorm使用pgsql的例子的更多相关文章

  1. PL/pgSQL的RETURN QUERY例子

    我的例子: 数据准备: create table custinfo(custid integer,callingcnt integer); ,),(,),(,); 函数生成: CREATE OR RE ...

  2. PL/pgSQL的 RETURN NEXT例子

    从网上找到例子: 可以说,RETURN NEXT要用在循环中: 例子一: 数据准备: CREATE TABLE foo (fooid INT, foosubid INT, fooname TEXT); ...

  3. PL/pgSQL的anyelement例子

    http://www.postgresonline.com/journal/archives/239-The-wonders-of-Any-Element.html 定义函数 pgsql=# CREA ...

  4. PL/pgSQL RETURNS TABLE 例子

    实验如下: RETURNS TABLE 中的变量名和SQL文中的变量名同名时,执行时会出错: pgsql=# create table sales(itemno integer,quantity in ...

  5. PL/pgSQL多输出参数例子

    例子一,不带returns: postgres=# CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS ...

  6. PL/pgSQL函数带output参数例子

    例子1,不带returns : [postgres@cnrd56 bin]$ ./psql psql () Type "help" for help. postgres=# CRE ...

  7. PL/pgSQL学习笔记之七

    http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 如果一个PL/pgSQL函数声明了输出参数,输出参数被赋予$n名 ...

  8. PL/pgSQL学习笔记之五

    http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 39.3. 声明 块中使用的所有的变量必须在块的声明节中进行声明 ...

  9. 2015第42周六Pgsql全文索引

    全文搜索通常也就是文本搜索,它可以提供满足查询的识别自然语言的能力,并且任意性地通过相关性查询进行排序.搜索最常见的类型就是找到所有包含给定的查询术语的记录,并且以相似性的查询顺序返回它们. 对于普通 ...

随机推荐

  1. Debian中如何切换默认Python版本

    当你安装 Debian Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件,你可以按照以下方法使用 ls 命令来查看你的系 ...

  2. FTP方式获取文件步骤

    1.在浏览器地址行输入FTP连接地址 2.进入FTP端之后,点击“檢視”-“在windows資源總覽中開啟FTP站臺”,這樣就可以打開FTP端的文件了

  3. codeforces 192 c

    link: http://codeforces.com/contest/330/problem/C broute force but you must be careful about some tr ...

  4. 【P1303】苹果二叉树

    树归入门题 原题: 有一棵苹果树,如果树枝有分叉,一定是分2叉(就是说没有只有1个儿子的结点).这棵树共有N个结点(叶子点或者树枝分叉点),编号为1-N,树根编号一定是1.我们用一根树枝两端连接的结点 ...

  5. C++@冒号(:)和双冒号(::)的用法

    转自:http://blog.csdn.net/zimingjushi/article/details/6549390 1.冒号(:)用法 (1)表示机构内位域的定义(即该变量占几个bit空间) ty ...

  6. Python小白好教程

    提供一些Python的基础教程. Crossin的编程教师:网址:http://crossincode.com/home/ 廖雪峰的官方网站 网址:http://www.liaoxuefeng.com ...

  7. python主文件判断

    目录结构: myfile1.py.myfile2.py.myfile3.py代码都是打印文件名和__name__变量,如myfile1.py: print("myfile1",__ ...

  8. 【计算机视觉领域】常用的 feature 提取方法,feature 提取工具包

    [计算机视觉领域]常用的 feature 提取方法,feature 提取工具包 利用 VL 工具包进行各种特征的提取: VL 工具包官网地址:http://www.vlfeat.org/index.h ...

  9. lucene文件格式待整理

    这是之前Lucene3.0生成的索引格式 a表

  10. cookies的理解

    设置cookie 每个cookie都是一个名/值对,可以把下面这样一个字符串赋值给document.cookie: document.cookie="userId=828"; 如果 ...