Skip to content

Commit 1acad49

Browse files
committed
fix: update motherduck.yaml to enhance SQL commands and metadata queries
1 parent 0914da5 commit 1acad49

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

core/dbio/templates/motherduck.yaml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
core:
22
drop_table: drop table if exists {table}
33
drop_view: drop view if exists {view}
4+
drop_index: drop index if exists {index}
5+
create_index: create index {index} on {table} ({cols})
6+
create_unique_index: create unique index {index} on {table} ({cols})
47
create_table: create table if not exists {table} ({col_types})
8+
create_temporary_table: create temp table if not exists {table} ({col_types})
59
replace: replace into {table} ({names}) values({values})
610
truncate_table: delete from {table}
711
insert_option: ""
812
modify_column: 'alter {column} type {type}'
913

10-
iceberg_scan: select {fields} from iceberg_scan('{uri}', allow_moved_paths = true) {where}
11-
delta_scan: select {fields} from delta_scan('{uri}') {where}
12-
parquet_scan: select {fields} from parquet_scan('{uri}') {where}
13-
1414

1515
metadata:
1616
databases: PRAGMA database_list
1717

1818
current_database: PRAGMA database_list
1919

2020
schemas: |
21-
select schema_name
21+
select distinct schema_name
2222
from information_schema.schemata
2323
order by schema_name
2424
@@ -40,22 +40,25 @@ metadata:
4040
columns: |
4141
select column_name, data_type, coalesce(numeric_precision, character_maximum_length) as precision, numeric_scale as scale
4242
from information_schema.columns
43-
where table_name = '{table}'
43+
where table_schema = '{schema}'
44+
and table_name = '{table}'
4445
order by ordinal_position
4546
4647
primary_keys: |
4748
select '{table}.key' as pk_name,
4849
constraint_index as position,
4950
replace(replace(constraint_text, 'PRIMARY KEY(', ''), ')', '') as column_name
5051
from duckdb_constraints()
51-
where table_name = '{table}'
52+
where table_schema = '{schema}'
53+
and table_name = '{table}'
5254
and constraint_type = 'PRIMARY KEY'
5355
5456
indexes: |
5557
select index_name as index_name,
5658
sql as column_name
5759
from duckdb_indexes()
58-
where table_name = '{table}'
60+
where table_schema = '{schema}'
61+
and table_name = '{table}'
5962
6063
columns_full: |
6164
with tables_cte as (
@@ -69,7 +72,8 @@ metadata:
6972
else false
7073
end as is_view
7174
from information_schema.tables
72-
where table_name = '{table}'
75+
where table_schema = '{schema}'
76+
and table_name = '{table}'
7377
)
7478
select
7579
cols.table_schema as schema_name,
@@ -95,6 +99,7 @@ metadata:
9599
end as is_view
96100
from information_schema.tables
97101
where 1=1
102+
{{if .schema -}} and table_schema = '{schema}' {{- end}}
98103
{{if .tables -}} and table_name in ({tables}) {{- end}}
99104
)
100105
select
@@ -111,10 +116,10 @@ metadata:
111116
order by cols.table_catalog, cols.table_schema, cols.table_name, cols.ordinal_position
112117
113118
ddl_table: |
114-
PRAGMA table_info('{table}')
119+
PRAGMA table_info('{schema}.{table}')
115120
116121
ddl_view: |
117-
PRAGMA table_info('{table}')
122+
PRAGMA table_info('{schema}.{table}')
118123
119124
analysis:
120125
chars: |
@@ -142,6 +147,7 @@ function:
142147
checksum_datetime: CAST((epoch({field}) || substr(strftime({field}, '%f'),4) ) as bigint)
143148
checksum_decimal: 'abs(cast({field} as bigint))'
144149
checksum_boolean: 'length({field}::string)'
150+
cast_to_text: 'cast({field} as text)'
145151

146152
variable:
147153
bool_as: integer

0 commit comments

Comments
 (0)