postgresql - sql support for []time.Time? -


i have postgres table as:

create table public.foo (     id uuid not null default gen_random_uuid(),     foo timestamp time zone[],     bar timestamp time zone ) 

i'm querying table , scanning result values as:

var res []myresstruct rows, err := db.query(`sql goes here`, &params) if err != nil {     log.printf("err querying: %v\n", err)     panic(err) } defer rows.close()  rows.next() {     var (         id   uuid.uuid         foo  []uint8         bar  time.time     )     if err := rows.scan(&id, &foo, &bar); err != nil {         log.printf("err scanning: %v\n", err)         panic(err)     }      // note: hate this, golang's sql driver doesn't support \     //       arrays of timestamps?     s := string(foo)     s = strings.replace(s, "{", "", -1)     s = strings.replace(s, "}", "", -1)     s = strings.replace(s, "\"", "", -1)     z := strings.split(s, ",")     var tmpfoo []time.time     _, v := range z {         t, _ := time.parse("2006-01-02 15:04:05-07", v)         tmpfoo = append(tmpfoo, t)     }      // note @adam-hanna: there way know length of results \     //                   can create slice of proper length?     res = append(res, &myresstruct{         id:   id,         foo:  tmpfoo,         bar:  bar,     }) }  if err := rows.err(); err != nil {     log.printf("rows.error(): %v\n", err)     panic(err) } 

why have use []uint8 foo can use time.time bar? there better way? fyi - i'm using lib/pq.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -