|
| 1 | +CREATE SERVER uint256_http_server FOREIGN DATA WRAPPER clickhouse_fdw |
| 2 | + OPTIONS (dbname 'uint256_test', driver 'http'); |
| 3 | +CREATE SERVER uint256_binary_server FOREIGN DATA WRAPPER clickhouse_fdw |
| 4 | + OPTIONS (dbname 'uint256_test', driver 'binary'); |
| 5 | +CREATE USER MAPPING FOR CURRENT_USER SERVER uint256_http_server; |
| 6 | +CREATE USER MAPPING FOR CURRENT_USER SERVER uint256_binary_server; |
| 7 | +CREATE SCHEMA uint256_http; |
| 8 | +CREATE SCHEMA uint256_binary; |
| 9 | +SELECT clickhouse_raw_query('DROP DATABASE IF EXISTS uint256_test'); |
| 10 | + clickhouse_raw_query |
| 11 | +---------------------- |
| 12 | + |
| 13 | +(1 row) |
| 14 | + |
| 15 | +SELECT clickhouse_raw_query('CREATE DATABASE uint256_test'); |
| 16 | + clickhouse_raw_query |
| 17 | +---------------------- |
| 18 | + |
| 19 | +(1 row) |
| 20 | + |
| 21 | +SELECT clickhouse_raw_query($$ |
| 22 | + CREATE TABLE uint256_test.wide_values ( |
| 23 | + id UInt8, |
| 24 | + u128 UInt128, |
| 25 | + u256 UInt256, |
| 26 | + n256 Nullable(UInt256), |
| 27 | + a256 Array(UInt256) |
| 28 | + ) ENGINE = MergeTree ORDER BY id |
| 29 | +$$); |
| 30 | + clickhouse_raw_query |
| 31 | +---------------------- |
| 32 | + |
| 33 | +(1 row) |
| 34 | + |
| 35 | +SELECT clickhouse_raw_query($$ |
| 36 | + INSERT INTO uint256_test.wide_values VALUES |
| 37 | + ( |
| 38 | + 0, |
| 39 | + toUInt128(0), |
| 40 | + toUInt256(0), |
| 41 | + NULL, |
| 42 | + [] |
| 43 | + ), |
| 44 | + ( |
| 45 | + 1, |
| 46 | + toUInt128('170141183460469231731687303715884105728'), |
| 47 | + toUInt256('57896044618658097711785492504343953926634992332820282019728792003956564819968'), |
| 48 | + toUInt256('57896044618658097711785492504343953926634992332820282019728792003956564819968'), |
| 49 | + [ |
| 50 | + toUInt256(0), |
| 51 | + toUInt256('57896044618658097711785492504343953926634992332820282019728792003956564819968') |
| 52 | + ] |
| 53 | + ), |
| 54 | + ( |
| 55 | + 2, |
| 56 | + toUInt128('340282366920938463463374607431768211455'), |
| 57 | + toUInt256('115792089237316195423570985008687907853269984665640564039457584007913129639935'), |
| 58 | + toUInt256('115792089237316195423570985008687907853269984665640564039457584007913129639935'), |
| 59 | + [toUInt256('115792089237316195423570985008687907853269984665640564039457584007913129639935')] |
| 60 | + ) |
| 61 | +$$); |
| 62 | + clickhouse_raw_query |
| 63 | +---------------------- |
| 64 | + |
| 65 | +(1 row) |
| 66 | + |
| 67 | +IMPORT FOREIGN SCHEMA uint256_test LIMIT TO (wide_values) |
| 68 | + FROM SERVER uint256_http_server INTO uint256_http; |
| 69 | +IMPORT FOREIGN SCHEMA uint256_test LIMIT TO (wide_values) |
| 70 | + FROM SERVER uint256_binary_server INTO uint256_binary; |
| 71 | +SELECT n.nspname AS schema_name, |
| 72 | + a.attname AS column_name, |
| 73 | + format_type(a.atttypid, a.atttypmod) AS postgres_type |
| 74 | +FROM pg_attribute AS a |
| 75 | +JOIN pg_class AS c ON c.oid = a.attrelid |
| 76 | +JOIN pg_namespace AS n ON n.oid = c.relnamespace |
| 77 | +WHERE n.nspname IN ('uint256_http', 'uint256_binary') |
| 78 | + AND c.relname = 'wide_values' |
| 79 | + AND a.attnum > 0 |
| 80 | + AND NOT a.attisdropped |
| 81 | + AND a.attname <> 'id' |
| 82 | +ORDER BY schema_name, column_name; |
| 83 | + schema_name | column_name | postgres_type |
| 84 | +----------------+-------------+--------------- |
| 85 | + uint256_binary | a256 | numeric[] |
| 86 | + uint256_binary | n256 | numeric |
| 87 | + uint256_binary | u128 | numeric |
| 88 | + uint256_binary | u256 | numeric |
| 89 | + uint256_http | a256 | numeric[] |
| 90 | + uint256_http | n256 | numeric |
| 91 | + uint256_http | u128 | numeric |
| 92 | + uint256_http | u256 | numeric |
| 93 | +(8 rows) |
| 94 | + |
| 95 | +SELECT id, u128, u256, n256, a256 |
| 96 | +FROM uint256_http.wide_values |
| 97 | +ORDER BY id; |
| 98 | + id | u128 | u256 | n256 | a256 |
| 99 | +----+-----------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+----------------------------------------------------------------------------------- |
| 100 | + 0 | 0 | 0 | | {} |
| 101 | + 1 | 170141183460469231731687303715884105728 | 57896044618658097711785492504343953926634992332820282019728792003956564819968 | 57896044618658097711785492504343953926634992332820282019728792003956564819968 | {0,57896044618658097711785492504343953926634992332820282019728792003956564819968} |
| 102 | + 2 | 340282366920938463463374607431768211455 | 115792089237316195423570985008687907853269984665640564039457584007913129639935 | 115792089237316195423570985008687907853269984665640564039457584007913129639935 | {115792089237316195423570985008687907853269984665640564039457584007913129639935} |
| 103 | +(3 rows) |
| 104 | + |
| 105 | +SELECT id, u128, u256, n256, a256 |
| 106 | +FROM uint256_binary.wide_values |
| 107 | +ORDER BY id; |
| 108 | + id | u128 | u256 | n256 | a256 |
| 109 | +----+-----------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+----------------------------------------------------------------------------------- |
| 110 | + 0 | 0 | 0 | | {} |
| 111 | + 1 | 170141183460469231731687303715884105728 | 57896044618658097711785492504343953926634992332820282019728792003956564819968 | 57896044618658097711785492504343953926634992332820282019728792003956564819968 | {0,57896044618658097711785492504343953926634992332820282019728792003956564819968} |
| 112 | + 2 | 340282366920938463463374607431768211455 | 115792089237316195423570985008687907853269984665640564039457584007913129639935 | 115792089237316195423570985008687907853269984665640564039457584007913129639935 | {115792089237316195423570985008687907853269984665640564039457584007913129639935} |
| 113 | +(3 rows) |
| 114 | + |
| 115 | +DROP USER MAPPING FOR CURRENT_USER SERVER uint256_http_server; |
| 116 | +DROP USER MAPPING FOR CURRENT_USER SERVER uint256_binary_server; |
| 117 | +SELECT clickhouse_raw_query('DROP DATABASE uint256_test'); |
| 118 | + clickhouse_raw_query |
| 119 | +---------------------- |
| 120 | + |
| 121 | +(1 row) |
| 122 | + |
| 123 | +DROP SERVER uint256_http_server CASCADE; |
| 124 | +NOTICE: drop cascades to foreign table uint256_http.wide_values |
| 125 | +DROP SERVER uint256_binary_server CASCADE; |
| 126 | +NOTICE: drop cascades to foreign table uint256_binary.wide_values |
| 127 | +DROP SCHEMA uint256_http; |
| 128 | +DROP SCHEMA uint256_binary; |
0 commit comments