mirror of
https://github.com/sasjs/core.git
synced 2026-01-03 15:40:05 +00:00
feat: Postgres support for getddl macro
This commit is contained in:
@@ -217,7 +217,72 @@ run;
|
||||
run;
|
||||
%end;
|
||||
%end;
|
||||
%else %if &flavour=PGSQL %then %do;
|
||||
/* if schema does not exist, set to be same as libref */
|
||||
%local schemaactual;
|
||||
proc sql noprint;
|
||||
select sysvalue into: schemaactual
|
||||
from dictionary.libnames
|
||||
where libname="&libref" and engine='POSTGRES';
|
||||
%let schema=%sysfunc(coalescec(&schemaactual,&schema,&libref));
|
||||
|
||||
%do x=1 %to %sysfunc(countw(&dsnlist));
|
||||
%let curds=%scan(&dsnlist,&x);
|
||||
data _null_;
|
||||
file &fref mod;
|
||||
put "/* Postgres Flavour DDL for &schema..&curds */";
|
||||
data _null_;
|
||||
file &fref mod;
|
||||
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
||||
length fmt $32;
|
||||
if _n_=1 then do;
|
||||
if memtype='DATA' then do;
|
||||
put "CREATE TABLE &schema..&curds (";
|
||||
end;
|
||||
else do;
|
||||
put "CREATE VIEW &schema..&curds (";
|
||||
end;
|
||||
put " "@@;
|
||||
end;
|
||||
else put " ,"@@;
|
||||
format=upcase(format);
|
||||
if 1=0 then; /* dummy if */
|
||||
%if &applydttm=YES %then %do;
|
||||
else if format=:'DATETIME' then fmt=' TIMESTAMP ';
|
||||
%end;
|
||||
else if type='num' then fmt=' DOUBLE PRECISION';
|
||||
else fmt='VARCHAR('!!cats(length)!!')';
|
||||
if notnull='yes' then notnul=' NOT NULL';
|
||||
put name fmt notnul;
|
||||
run;
|
||||
data _null_;
|
||||
length ds $128;
|
||||
set &idxinfo (where=(memname="&curds"));
|
||||
file &fref mod;
|
||||
by idxusage indxname;
|
||||
if unique='yes' then uniq=' unique';
|
||||
ds=cats(libname,'.',memname);
|
||||
if first.indxname then do;
|
||||
if unique='yes' and nomiss='yes' then do;
|
||||
put ' ,PRIMARY KEY ';
|
||||
end;
|
||||
else if unique='yes' then do;
|
||||
/* add nonclustered in case of multiple unique indexes */
|
||||
put ' ,UNIQUE ';
|
||||
end;
|
||||
put ' (' name ;
|
||||
end;
|
||||
else put ' ,' name ;
|
||||
if last.indxname then do;
|
||||
put ' )';
|
||||
end;
|
||||
run;
|
||||
data _null_;
|
||||
file &fref mod;
|
||||
put ');';
|
||||
run;
|
||||
%end;
|
||||
%end;
|
||||
%if &showlog=YES %then %do;
|
||||
options ps=max;
|
||||
data _null_;
|
||||
|
||||
Reference in New Issue
Block a user