Giter Club home page Giter Club logo

Comments (1)

rpbouman avatar rpbouman commented on August 15, 2024

For reference, piece of code that I used to find this out:

const duckdb = require('duckdb');

const db = new duckdb.Database(':memory:');
const sql = `
  select
    1::BIGINT                                     as "_bigint"          --	INT8, LONG	signed eight-byte integer
  , '01'::BIT                                     as "_bit"             --	BITSTRING	string of 1s and 0s
  , 'ab'::BLOB	                                  as "_blob"            --  BYTEA, BINARY, VARBINARY	variable-length binary data
  , 1::BOOLEAN	                                  as "_boolean"         --  BOOL, LOGICAL	logical boolean (true/false)
  , current_date                                  as "_date"            --  DATE	 	calendar date (year, month day)
  , 'epoch'::DATE                                  as "_epoch"
  , 'infinity'::DATE                              as "_infinity_date"
  , '-infinity'::DATE                              as "_-infinity_date"
  , 3.1415::REAL	                                as "_real"            --  FLOAT4, FLOAT	single precision floating-point number (4 bytes)
  , 3.1415::DECIMAL(5,4)	                        as "_decimal(5,4)"     
  , 3.1415::DOUBLE	                              as "_double1"           --  FLOAT8,	double precision floating-point number (8 bytes)
  , (0.1 * 0.2)::DECIMAL(19,18)                   as "_decimal(19,18)"
  , (0.1 * 0.2)::DECIMAL(19,18)                   as "_decimal(19,18)"
  , 5.1::DOUBLE * 100                             as "_double"
  , 5.1::DECIMAL(2,1) * 100                       as "_decimal(2,1)"
  , 1::HUGEINT	 	                                as "_hugeint"          --  signed sixteen-byte integer
  , 2::INTEGER	                                  as "_integer"          --  INT4, INT, SIGNED	signed four-byte integer
  , 'Infinity'::DOUBLE                                    as "_infinity"
  , '-Infinity'::DOUBLE                                     as "_-infinity"
  , 'NaN'::DOUBLE                                           as "_NaN"
  , null::double                                  as "_null"
  , INTERVAL 1 second                             as "_interval1s"         --  date / time delta
  , INTERVAL 1 year                               as "_interval1y"         --  date / time delta
  , 42::SMALLINT	                                as "_smallint"         --  INT2, SHORT	signed two-byte integer
  , TIME   '1992-09-20 11:30:00.123756'          	as "_time1"             --  time of day (no time zone)
  , TIME   '1992-09-20 01:30:00.123456'          	as "_time2"             --  time of day (no time zone)
  , TIMESTAMPTZ '1992-09-20 11:30:00.123756789'   as "_timestamptz"      --	TIMESTAMPTZ	combination of time and date that uses the current time zone
  , TIMESTAMP '1992-09-20 11:30:00.123999999'	    as "_timestamp"        --  DATETIME	combination of time and date
  , 1::TINYINT	                                  as "_tinyint"          -- INT1	signed one-byte integer
  , 1::UBIGINT	 	                                as "_ubugint"          -- unsigned eight-byte integer
  , 1::UHUGEINT	 	                                as "_uhugeint"         -- unsigned sixteen-byte integer
  , 1::UINTEGER	 	                                as "_uinteger"         -- unsigned four-byte integer
  , 1::USMALLINT	 	                              as "_usmallint"        -- unsigned two-byte integer
  , 1::UTINYINT	 	                                as "_utinyint"         -- unsigned one-byte integer
  , gen_random_uuid()::UUID	 	                    as "_uuid"             -- UUID data type
  , 'bla'::VARCHAR                                as "_varchar"
  , [1, 2, 3]                                     as "_list"
  , MAP {'key1': 1, 'key2': 2}            as "_map"
  , {'x': 1, 'y': 2, 'z': 3}                      as "_struct"
  , 'a'::ENUM('a', 'b')                           as "_enum" 
  , [1::BIGINT]                                   as "_[bigint]"          --	INT8, LONG	signed eight-byte integer
  , ['01'::BIT]                                   as "_[bit]"             --	BITSTRING	string of 1s and 0s
  , ['ab'::BLOB]	                                as "_[blob]"            --  BYTEA, BINARY, VARBINARY	variable-length binary data
  , [1::BOOLEAN]	                                as "_[boolean]"         --  BOOL, LOGICAL	logical boolean (true/false)
  , [current_date]                                as "_[date]"            --  DATE	 	calendar date (year, month day)
  , [3.1415::REAL]	                              as "_[real]"            --  FLOAT4, FLOAT	single precision floating-point number (4 bytes)
  , [3.1415::DECIMAL(5,4)]	                      as "_[decimal(5,4)]"     
  , [3.1415::DOUBLE]	                            as "_[double1]"           --  FLOAT8,	double precision floating-point number (8 bytes)
  , [(0.1 * 0.2)::DECIMAL(19,18)]                 as "_[decimal(19,18)]"
  , [5.1::DOUBLE * 100]                           as "_[double]"
  , [5.1::DECIMAL(2,1) * 100]                     as "_[decimal(2,1)]"
  , [1::HUGEINT]	 	                              as "_[hugeint]"          --  signed sixteen-byte integer
  , [2::INTEGER]	                                as "_[integer]"          --  INT4, INT, SIGNED	signed four-byte integer
  , [INTERVAL 1 year]                             as "_[interval1y]"         --  date / time delta
  , [42::SMALLINT]	                              as "_[smallint]"         --  INT2, SHORT	signed two-byte integer
  , [TIME '1992-09-20 01:30:00.123756']          	as "_[time1]"             --  time of day (no time zone)
  , [TIME '1992-09-20 11:30:00.123456']          	as "_[time2]"             --  time of day (no time zone)
  , [TIMESTAMPTZ '1992-09-20 11:30:00.123456789'] as "_[timestamptz]"      --	TIMESTAMPTZ	combination of time and date that uses the current time zone
  , [TIMESTAMP '1992-09-20 11:30:00.123456789']	  as "_[timestamp]"        --  DATETIME	combination of time and date
  , [1::TINYINT]	                                as "_[tinyint]"          -- INT1	signed one-byte integer
  , [1::UBIGINT]	 	                              as "_[ubugint]"          -- unsigned eight-byte integer
  , [1::UHUGEINT]	 	                              as "_[uhugeint]"         -- unsigned sixteen-byte integer
  , [1::UINTEGER]	 	                              as "_[uinteger]"         -- unsigned four-byte integer
  , [1::USMALLINT]	 	                            as "_[usmallint]"        -- unsigned two-byte integer
  , [1::UTINYINT]	 	                              as "_[utinyint]"         -- unsigned one-byte integer
  , [gen_random_uuid()::UUID]	 	                  as "_[uuid]"             -- UUID data type
  , ['bla'::VARCHAR]                              as "_[varchar]"
`;
db.all(sql, function(err, res) {
  if (err) {
    console.warn(err);
    return;
  }
  const row = res[0];
  const keys = Object.keys(row);

  for (let i = 0; i < keys.length; i++){
    const key = keys[i];
    const value = row[key];
    let type = typeof value;
    if (key.startsWith('_interval')) {
      type += ' ' + JSON.stringify(Object.keys(value).reduce(function(acc, curr){
        acc[curr] = typeof value[curr];
        return acc ;
      }, {}));
    }
    const ctor = value ? value.constructor : undefined;
    console.log('column: ', key, '; type: ', type, '; value: ', value, '; constructor: ', String(ctor));
    if (value instanceof Date) {
      console.log(value.getMilliseconds());
    }
  }
  //console.log(obj);
});

from duckdb-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.