Class: DuckDB::Column
- Inherits:
-
Object
- Object
- DuckDB::Column
- Defined in:
- lib/duckdb/column.rb,
ext/duckdb/column.c
Instance Method Summary collapse
-
#name ⇒ Object
Returns the column name.
-
#type ⇒ Object
returns column type symbol ‘:unknown` means that the column type is unknown/unsupported by ruby-duckdb.
Instance Method Details
#name ⇒ Object
Returns the column name.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'ext/duckdb/column.c', line 57
VALUE duckdb_column_get_name(VALUE oDuckDBColumn) {
rubyDuckDBColumn *ctx;
VALUE result;
rubyDuckDBResult *ctxresult;
TypedData_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, &column_data_type, ctx);
result = rb_ivar_get(oDuckDBColumn, rb_intern("result"));
ctxresult = get_struct_result(result);
return rb_utf8_str_new_cstr(duckdb_column_name(&(ctxresult->result), ctx->col));
}
|
#type ⇒ Object
returns column type symbol ‘:unknown` means that the column type is unknown/unsupported by ruby-duckdb. `:invalid` means that the column type is invalid in duckdb.
require 'duckdb'
db = DuckDB::Database.open
con = db.connect
con.query('CREATE TABLE users (id INTEGER, name VARCHAR(30))')
users = con.query('SELECT * FROM users')
columns = users.columns
columns.first.type #=> :integer
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/duckdb/column.rb', line 19 def type types = %i[ invalid boolean tinyint smallint integer bigint utinyint usmallint uinteger ubigint float double timestamp date time interval hugeint varchar blob decimal timestamp_s timestamp_ms timestamp_ns enum list struct map uuid json ] if Gem::Version.new(DuckDB::LIBRARY_VERSION) == Gem::Version.new('0.10.0') types[17, 0] = :uhugeint end index = _type return :unknown if index >= types.size types[index] end |