class DuckDB::TableDescription
DuckDB::TableDescription provides metadata about a table in DuckDB.
Use it to retrieve column descriptions — including name, logical type, and whether a column has a default value — for any accessible table.
Requires DuckDB >= 1.5.0.
require 'duckdb' db = DuckDB::Database.open con = db.connect con.query('CREATE TABLE users (id INTEGER, name VARCHAR DEFAULT \'anonymous\')') td = DuckDB::TableDescription.new(con, 'users') td.column_descriptions.each do |cd| puts "#{cd.name}: #{cd.logical_type.type}, default=#{cd.has_default?}" end # id: integer, default=false # name: varchar, default=true
Public Class Methods
Source
# File lib/duckdb/table_description.rb, line 45 def initialize(con, table, schema: nil, catalog: nil) raise DuckDB::Error, '1st argument must be DuckDB::Connection object.' unless con.is_a?(DuckDB::Connection) raise DuckDB::Error, '2nd argument must be table name.' if table.nil? table, schema, catalog = parse_table_name(table, schema, catalog) raise DuckDB::Error, error_message unless _initialize(con, catalog, schema, table) end
Creates a new TableDescription for the given table.
con must be a DuckDB::Connection. table is the table name (String). Optionally pass schema: and/or catalog: to qualify the table.
The table argument supports dot-notation and quoting:
-
'schema.table'— interpreted as schema-qualified (deprecated; useschema:instead) -
'"a.b"'or"'a.b'"— treated as a literal table name containing a dot
Raises DuckDB::Error if the connection is invalid, the table name is nil, or the table (or schema/catalog) does not exist.
require 'duckdb' db = DuckDB::Database.open con = db.connect con.query('CREATE TABLE t (i INTEGER)') DuckDB::TableDescription.new(con, 't') DuckDB::TableDescription.new(con, 't', schema: 'main')
Public Instance Methods
Source
# File lib/duckdb/table_description.rb, line 66 def column_descriptions Array.new(_column_count) do |i| ColumnDescription.new( name: _column_name(i), logical_type: _column_logical_type(i), has_default: _column_has_default?(i) ) end end
Returns an array of DuckDB::ColumnDescription objects, one per column.
Each element describes a single column’s name, logical type, and whether it has a default value defined.
require 'duckdb' db = DuckDB::Database.open con = db.connect con.query("CREATE TABLE t (i INTEGER, j INTEGER DEFAULT 5)") td = DuckDB::TableDescription.new(con, 't') td.column_descriptions #=> [#<data DuckDB::ColumnDescription name="i" ...>, ...]
Source
static VALUE table_description_error_message(VALUE self) {
rubyDuckDBTableDescription *ctx = get_struct_table_description(self);
const char *p = duckdb_table_description_error(ctx->table_description);
return p ? rb_str_new2(p) : Qnil;
}