Skip to content

Commit

Permalink
Merge pull request #50 from future-architect/feature/dump
Browse files Browse the repository at this point in the history
Fix: select exists records: number of field descriptions must equal number of destinations, got 6 and 20
  • Loading branch information
ma91n authored Feb 28, 2024
2 parents 08bed4b + 18d2006 commit 9bef618
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cli/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/jackc/pgtype"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/xuri/excelize/v2"
Expand Down Expand Up @@ -37,6 +38,8 @@ var query = `SELECT tab.relname AS table_name
ON tab.relid = coldesc.objoid
AND col.ordinal_position = coldesc.objsubid
WHERE exists(select 1 FROM tmp_exceltesting_dump_table_name WHERE tab.relname = name)
AND tab.schemaname = current_schema()
AND col.table_schema = current_schema()
ORDER BY tab.relname
, col.ordinal_position
;
Expand All @@ -59,6 +62,9 @@ var queryAll = `SELECT tab.relname AS table_name
LEFT OUTER JOIN pg_description coldesc
ON tab.relid = coldesc.objoid
AND col.ordinal_position = coldesc.objsubid
WHERE
tab.schemaname = current_schema()
AND col.table_schema = current_schema()
ORDER BY tab.relname
, col.ordinal_position
;
Expand Down Expand Up @@ -343,6 +349,12 @@ func fmtCell(a any) string {
switch v := a.(type) {
case time.Time:
return v.Format("2006-01-02 15:04:05")
case pgtype.Numeric:
var s string
if err := v.AssignTo(&s); err != nil {
return fmt.Sprintf("%v (fmtCell): %v", v, err)
}
return s
default:
return fmt.Sprint(v)
}
Expand Down

0 comments on commit 9bef618

Please sign in to comment.