Make UDT's that aren't enums fall through
- This allows typse that are not enumerations to properly escape the enumeration code in the query. - Fix #131
This commit is contained in:
parent
7a8d78cceb
commit
112a836af2
1 changed files with 5 additions and 2 deletions
|
@ -3,6 +3,7 @@ package drivers
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
// Side-effect import sql driver
|
// Side-effect import sql driver
|
||||||
|
@ -132,7 +133,7 @@ func (p *PostgresDriver) Columns(schema, tableName string) ([]bdb.Column, error)
|
||||||
select
|
select
|
||||||
c.column_name,
|
c.column_name,
|
||||||
(
|
(
|
||||||
case when c.data_type = 'USER-DEFINED' and c.udt_name <> 'hstore'
|
case when pgt.typtype = 'e'
|
||||||
then
|
then
|
||||||
(
|
(
|
||||||
select 'enum.' || c.udt_name || '(''' || string_agg(labels.label, ''',''') || ''')'
|
select 'enum.' || c.udt_name || '(''' || string_agg(labels.label, ''',''') || ''')'
|
||||||
|
@ -176,6 +177,8 @@ func (p *PostgresDriver) Columns(schema, tableName string) ([]bdb.Column, error)
|
||||||
)) as is_unique
|
)) as is_unique
|
||||||
|
|
||||||
from information_schema.columns as c
|
from information_schema.columns as c
|
||||||
|
inner join pg_namespace as pgn on pgn.nspname = c.udt_schema
|
||||||
|
left join pg_type pgt on c.data_type = 'USER-DEFINED' and pgn.oid = pgt.typnamespace and c.udt_name = pgt.typname
|
||||||
left join information_schema.element_types e
|
left join information_schema.element_types e
|
||||||
on ((c.table_catalog, c.table_schema, c.table_name, 'TABLE', c.dtd_identifier)
|
on ((c.table_catalog, c.table_schema, c.table_name, 'TABLE', c.dtd_identifier)
|
||||||
= (e.object_catalog, e.object_schema, e.object_name, e.object_type, e.collection_type_identifier))
|
= (e.object_catalog, e.object_schema, e.object_name, e.object_type, e.collection_type_identifier))
|
||||||
|
@ -349,7 +352,7 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column {
|
||||||
c.DBType = "hstore"
|
c.DBType = "hstore"
|
||||||
} else {
|
} else {
|
||||||
c.Type = "string"
|
c.Type = "string"
|
||||||
fmt.Printf("Warning: Incompatible data type detected: %s\n", c.UDTName)
|
fmt.Fprintln(os.Stderr, "Warning: Incompatible data type detected: %s\n", c.UDTName)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
c.Type = "null.String"
|
c.Type = "null.String"
|
||||||
|
|
Loading…
Add table
Reference in a new issue