1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-10 22:14:35 +00:00

feat: supporting postgres timestamps for mp_ds2inserts and mp_lib2inserts

This commit is contained in:
Allan Bowe
2021-08-24 20:39:02 +03:00
parent 5c936ddb65
commit 9f60d827b6
3 changed files with 32 additions and 4 deletions

18
all.sas
View File

@@ -3591,10 +3591,13 @@ run;
options: options:
@li SAS (default) - suitable for regular proc sql @li SAS (default) - suitable for regular proc sql
@li PGSQL - Used for Postgres databases @li PGSQL - Used for Postgres databases
@param [in] applydttm= (YES) If YES, any columns using datetime formats will
be converted to native DB datetime literals
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_existfileref.sas @li mf_existfileref.sas
@li mf_getvarcount.sas @li mf_getvarcount.sas
@li mf_getvarformat.sas
@li mf_getvarlist.sas @li mf_getvarlist.sas
@li mf_getvartype.sas @li mf_getvartype.sas
@@ -3603,6 +3606,7 @@ run;
**/ **/
%macro mp_ds2inserts(ds, outref=0,schema=0,outds=0,flavour=SAS,maxobs=max %macro mp_ds2inserts(ds, outref=0,schema=0,outds=0,flavour=SAS,maxobs=max
,applydttm=YES
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%if not %sysfunc(exist(&ds)) %then %do; %if not %sysfunc(exist(&ds)) %then %do;
@@ -3680,10 +3684,11 @@ data _null_;
length _____str $32767; length _____str $32767;
format _numeric_ best.; format _numeric_ best.;
format _character_ ; format _character_ ;
%local i comma var vtype; %local i comma var vtype vfmt;
%do i=1 %to %sysfunc(countw(&varlist)); %do i=1 %to %sysfunc(countw(&varlist));
%let var=%scan(&varlist,&i); %let var=%scan(&varlist,&i);
%let vtype=%mf_getvartype(&ds,&var); %let vtype=%mf_getvartype(&ds,&var);
%let vfmt=%upcase(%mf_getvarformat(&ds,&var,force=1));
%if &i=1 %then %do; %if &i=1 %then %do;
%if &flavour=SAS %then %do; %if &flavour=SAS %then %do;
put "insert into &schema.&outds set "; put "insert into &schema.&outds set ";
@@ -3713,7 +3718,12 @@ data _null_;
%end; %end;
%else %if &flavour=PGSQL %then %do; %else %if &flavour=PGSQL %then %do;
if missing(&var) then put 'NULL'; if missing(&var) then put 'NULL';
else put &var; %if &applydttm=YES and "%substr(&vfmt,1,8)"="DATETIME" %then %do;
else put "TIMESTAMP '" &var E8601DT25.6 "'";
%end;
%else %do;
else put &var;
%end;
%end; %end;
%end; %end;
%else %do; %else %do;
@@ -5725,6 +5735,8 @@ select distinct lowcase(memname)
@param [out] outref= Output fileref in which to create the insert statements. @param [out] outref= Output fileref in which to create the insert statements.
If it exists, it will be appended to, otherwise it will be created. If it exists, it will be appended to, otherwise it will be created.
@param [out] schema= (0) The schema of the target database, or the libref. @param [out] schema= (0) The schema of the target database, or the libref.
@param [in] applydttm= (YES) If YES, any columns using datetime formats will
be converted to native DB datetime literals
@version 9.2 @version 9.2
@author Allan Bowe @author Allan Bowe
@@ -5735,6 +5747,7 @@ select distinct lowcase(memname)
,outref=0 ,outref=0
,schema=0 ,schema=0
,maxobs=max ,maxobs=max
,applydttm=YES
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
/* Find the tables */ /* Find the tables */
@@ -5764,6 +5777,7 @@ select distinct lowcase(memname)
,outds=&ds ,outds=&ds
,flavour=&flavour ,flavour=&flavour
,maxobs=&maxobs ,maxobs=&maxobs
,applydttm=&applydttm
) )
%end; %end;

View File

@@ -25,10 +25,13 @@
options: options:
@li SAS (default) - suitable for regular proc sql @li SAS (default) - suitable for regular proc sql
@li PGSQL - Used for Postgres databases @li PGSQL - Used for Postgres databases
@param [in] applydttm= (YES) If YES, any columns using datetime formats will
be converted to native DB datetime literals
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_existfileref.sas @li mf_existfileref.sas
@li mf_getvarcount.sas @li mf_getvarcount.sas
@li mf_getvarformat.sas
@li mf_getvarlist.sas @li mf_getvarlist.sas
@li mf_getvartype.sas @li mf_getvartype.sas
@@ -37,6 +40,7 @@
**/ **/
%macro mp_ds2inserts(ds, outref=0,schema=0,outds=0,flavour=SAS,maxobs=max %macro mp_ds2inserts(ds, outref=0,schema=0,outds=0,flavour=SAS,maxobs=max
,applydttm=YES
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%if not %sysfunc(exist(&ds)) %then %do; %if not %sysfunc(exist(&ds)) %then %do;
@@ -114,10 +118,11 @@ data _null_;
length _____str $32767; length _____str $32767;
format _numeric_ best.; format _numeric_ best.;
format _character_ ; format _character_ ;
%local i comma var vtype; %local i comma var vtype vfmt;
%do i=1 %to %sysfunc(countw(&varlist)); %do i=1 %to %sysfunc(countw(&varlist));
%let var=%scan(&varlist,&i); %let var=%scan(&varlist,&i);
%let vtype=%mf_getvartype(&ds,&var); %let vtype=%mf_getvartype(&ds,&var);
%let vfmt=%upcase(%mf_getvarformat(&ds,&var,force=1));
%if &i=1 %then %do; %if &i=1 %then %do;
%if &flavour=SAS %then %do; %if &flavour=SAS %then %do;
put "insert into &schema.&outds set "; put "insert into &schema.&outds set ";
@@ -147,7 +152,12 @@ data _null_;
%end; %end;
%else %if &flavour=PGSQL %then %do; %else %if &flavour=PGSQL %then %do;
if missing(&var) then put 'NULL'; if missing(&var) then put 'NULL';
else put &var; %if &applydttm=YES and "%substr(&vfmt,1,8)"="DATETIME" %then %do;
else put "TIMESTAMP '" &var E8601DT25.6 "'";
%end;
%else %do;
else put &var;
%end;
%end; %end;
%end; %end;
%else %do; %else %do;

View File

@@ -28,6 +28,8 @@
@param [out] outref= Output fileref in which to create the insert statements. @param [out] outref= Output fileref in which to create the insert statements.
If it exists, it will be appended to, otherwise it will be created. If it exists, it will be appended to, otherwise it will be created.
@param [out] schema= (0) The schema of the target database, or the libref. @param [out] schema= (0) The schema of the target database, or the libref.
@param [in] applydttm= (YES) If YES, any columns using datetime formats will
be converted to native DB datetime literals
@version 9.2 @version 9.2
@author Allan Bowe @author Allan Bowe
@@ -38,6 +40,7 @@
,outref=0 ,outref=0
,schema=0 ,schema=0
,maxobs=max ,maxobs=max
,applydttm=YES
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
/* Find the tables */ /* Find the tables */
@@ -67,6 +70,7 @@ select distinct lowcase(memname)
,outds=&ds ,outds=&ds
,flavour=&flavour ,flavour=&flavour
,maxobs=&maxobs ,maxobs=&maxobs
,applydttm=&applydttm
) )
%end; %end;