dbsrgits / sql-translator

SQL::Translator (SQLFairy)
http://sqlfairy.sourceforge.net/
82 stars 90 forks source link

Add support for 'default' parameter #119

Open KES777 opened 5 years ago

KES777 commented 5 years ago

code example:

    $sqlt->add_procedure(
        name =>  'order_total_suma',
        parameters =>  [
            { argmode => 'in',  name => '_deep',          type => 'tstzrange', default => 1 },
        ],
...

expected SQL:

CREATE FUNCTION "order_total_suma" (in _deep tstzrange default 1)  ...
KES777 commented 5 years ago
--- a/lib/SQL/Translator/Producer/PostgreSQL.pm
+++ b/lib/SQL/Translator/Producer/PostgreSQL.pm
@@ -756,9 +756,13 @@ sub create_procedure {
   my @args = ();
   foreach my $arg (@{$procedure->parameters}) {
     $arg = {name => $arg} if ref($arg) ne 'HASH';
-    push @args, join(' ', map $arg->{$_},
+    my $param =  join(' ', map $arg->{$_},
                           grep defined($arg->{$_}),
                           qw/argmode name type/);
+    if( defined $arg->{ default } ) {
+        $param .= ' default ' .$arg->{ default };
+    }
+    push @args, $param;
   }
   $sql .= join(', ', @args);
   $sql .= ')';
KES777 commented 1 year ago

@rabbiveesh Hello. I saw recent updates. Is there a chance to apply this?