Skip to content

[Request] fread - input plain SQL script #878

Description

@jangorecki

Proposed feature request:

I don't know how complex it would be, but maybe we can just map SQL INSERT statements values into columns accepted as fread's input?

INSERT INTO tbl(col1, col2, col3, col4) VALUES (1, 'asd', 923123123, 'zx');
INSERT INTO tbl(col1, col3, col4) VALUES (2, 923123123, 'zxz');
INSERT INTO tbl(col1, col2, col3) VALUES (3, 'asd3', 923123123);

or at least full column set

INSERT INTO tbl VALUES (1, 'asd', 923123123, 'zx');
INSERT INTO tbl VALUES (1,NULL,923123123,'zxz');
INSERT INTO tbl VALUES (3, 'asd3', 923123123, NULL);

and the results would be:

data.table(col1 = c(1,2,3), col2 = c('asd',NA,'asd3'), col3 = c(923123123,923123123,923123123), col4 = c('zx','zxz','NA'))
>    col1 col2      col3 col4
> 1:    1  asd 923123123   zx
> 2:    2   NA 923123123  zxz
> 3:    3 asd3 923123123   NA

there are multiple (or even tons) of systems which export/import data using such scripts.
I think it could be handy but it is not a high priority.

Activity

  1. changed the title [-]fread - input plain SQL script[/-] [+][Request] fread - input plain SQL script[/+] on Nov 13, 2014
  2. jangorecki commented on Aug 15, 2015

    @jangorecki
    MemberAuthor

    Following fread input command seems to handle the process more or less:

    fread('awk -F\' *[(),]+ *\' -v OFS=, \'{for (i=2;i<NF;i++) printf "%s%s", ($i=="NULL"?"":$i), (i<(NF-1)?OFS:ORS)}\' insert_script.sql')
    #    V1     V2        V3    V4
    # 1:  1  'asd' 923123123  'zx'
    # 2:  1        923123123 'zxz'
    # 3:  3 'asd3' 923123123        

    As I see that process quite valuable (there are tons of software which can produce sql insert scripts) I think it could be added to FAQ (or fread vignette?) and the issue could be resolved.

  3. jangorecki commented on Mar 29, 2016

    @jangorecki
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions