I was trying to understand why it is happening but I could not find it. SQL Queries executes twice.
piece of my script:
my $driver = "Pg"; # Driver Name
my $database = $ARGV[0]; # First argument will be database name
my $dsn = "DBI:$driver:dbname=$database;host=127.0.0.1;port=5432";
my $userid = $ARGV[1]; # second argument will be username
my $password = $ARGV[2]; # third argument will be passwd
my $dbh = DBI->connect($dsn,$userid,$password, {RaiseError => 1 }) or die $DBI::errstr;
sub f_createUser {
if (scalar @_ != 3 ) {
return;
}
my $query = $dbh->prepare(qq{ SELECT createUserWithPassword(?,?) });
#my $result = $dbh->do($query) < 0 ? say "$DBI::errstr" : "# >>> Query worked successfully";
$query->execute($_[1],$_[2]);
}
&f_createUser(@revelantArray);
When I execute script, I got:
DBD::Pg::st execute failed: ERROR: role "tesstt" already exists CONTEXT: SQL statement "CREATE USER tesstt WITH PASSWORD '123'" PL/pgSQL function createuserwithpassword(character varying,character varying) line 3 at EXECUTE statement at homework2.pl line 39, line 1. DBD::Pg::st execute failed: ERROR: role "tesstt" already exists CONTEXT: SQL statement "CREATE USER tesstt WITH PASSWORD '123'" PL/pgSQL function createuserwithpassword(character varying,character varying) line 3 at EXECUTE statement at homework2.pl line 39, line 1.
Why is this happening ? What am I missing ?
Thanks in advance...