GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — PostgreSQL arrays can have NULL items · Issue #185 · sqlc-dev/sqlc Open Labels DescriptionGiven the following schema and query: CREATE TABLE foo ( id text NOT NULL, tags text[] ); -- name: ListFoo :many SELECT * FROM foo; sqlc will generate the following code: // Code generated by sqlc. DO NOT EDIT. package main import ( "context" "database/sql" "github.com/lib/pq" ) type Foo struct { ID sql.NullString Tags []string } const listFoo = `-- name: ListFoo :many SELECT id, tags FROM foo ` func (q *Queries) ListFoo(ctx context.Context) ([]Foo, error) { rows, err := q.db.QueryContext(ctx, listFoo) if err != nil { return nil, err } defer rows.Close() var items []Foo for rows.Next() { var i Foo if err := rows.Scan(&i.ID, pq.Array(&i.Tags)); err != nil { return nil, err } items = append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } type DBTX interface { ExecContext(context.Context, string, ...interface{}) (sql.Result, error) PrepareContext(context.Context, string) (*sql.Stmt, error) QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) *sql.Row } func New(db DBTX) *Queries { return &Queries{db: db} } type Queries struct { db DBTX } func (q *Queries) WithTx(tx *sql.Tx) *Queries { return &Queries{ db: tx, } } With the following two records inserted into the INSERT INTO foo (id, tags) VALUES ('one', NULL); INSERT INTO foo (id, tags) VALUES ('two', array['tag']); However, if a NULL item exists in the INSERT INTO foo (id, tags) VALUES ('one', array[NULL]); That's not a problem, right? We'll just mark the Note that Reacted by Emanuel Pilz and Hibiki Seki Activity
MetadataMetadataAssigneesLabelsTypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |