pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
RV: calling a pl/pgsql function with array in argument
2+ messages / 2 participants
[nested] [flat]

* RV: calling a pl/pgsql function with array in argument
@ 2002-04-22 20:18  Ruben Vivas <ruben.vivas@explorersystem.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Ruben Vivas @ 2002-04-22 20:18 UTC (permalink / raw)
  To: pgsql-php

Hello, i am tryin to pass an array like argument to a pl/pgsql function but
i can not find the correct data type in te function.

i am using php.

ex: $dato[][] is the array using php, and i need call:

1. $res = fn_vea ($dato);   ?????

2. in pl/pgsql CREATE FUNCTION fn_vea (integer [][]) RETURNS varchar (25) AS
.........


does it work??
thank you




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: RV: calling a pl/pgsql function with array in argument
@ 2002-04-22 22:53  Papp, Gyozo <pgerzson@freestart.hu>
  parent: Ruben Vivas <ruben.vivas@explorersystem.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Papp, Gyozo @ 2002-04-22 22:53 UTC (permalink / raw)
  To: Ruben Vivas <ruben.vivas@explorersystem.com>; pgsql-php

this is a little bit hidden information somewhere in the manual.
Array types is the same the corresponding data type but 
prepended with an underscore '_', e.g:

_int4
_date
_smallint

btw, you cannot pass PHP array to plpgsql function. You need to 
convert it to string like:

 {1,2,23,45}

{   -- start array 
,,  -- comma separated values 
}   -- closing tag

here is my quote function to PG:

function quote($var, $type, $empty_null = TRUE)
{
 if ( empty($var) && $empty_null ){
  return 'NULL';
 }
 if ( $type{0} == '_' ){
  $type = substr($type, 1);
  $temp = "'{";
  foreach ( $var as $item ){
   $temp .= quote($item, $type).',';
  }
  $temp = substr($temp, 0, -1);
  return $temp ."}'";
 }
 switch ( $type ){
 case 'int':
  return intval($var);
 case 'bool':
  return ($var ? "'t'::bool": "'f'::bool"); 
 case 'date':
  if ( is_numeric($var) ) { // echo timestamp-kent kezeli
   return date("'Y-m-d'", $var);
  }
  // ha ez sem, akkor sima szovegkent tovabbadja
 case 'text':
  if (!get_magic_quotes_gpc()) {
    $var = addslashes($var);
  }
  return '\''.$var.'\'';
 default: trigger_error("unknown type : $type ($value)", E_USER_ERROR);
 }
} 
----- Original Message ----- 
From: "Ruben Vivas" <ruben.vivas@explorersystem.com>
To: <pgsql-php@postgresql.org>
Sent: Monday, April 22, 2002 10:18 PM
Subject: [PHP] RV: calling a pl/pgsql function with array in argument


| Hello, i am tryin to pass an array like argument to a pl/pgsql function but
| i can not find the correct data type in te function.
| 
| i am using php.
| 
| ex: $dato[][] is the array using php, and i need call:
| 
| 1. $res = fn_vea ($dato);   ?????
| 
| 2. in pl/pgsql CREATE FUNCTION fn_vea (integer [][]) RETURNS varchar (25) AS
| .........
| 
| 
| does it work??
| thank you
| 
| 
| ---------------------------(end of broadcast)---------------------------
| TIP 6: Have you searched our list archives?
| 
| http://archives.postgresql.org




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-04-22 22:53 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-22 20:18 RV: calling a pl/pgsql function with array in argument Ruben Vivas <ruben.vivas@explorersystem.com>
2002-04-22 22:53 ` Papp, Gyozo <pgerzson@freestart.hu>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox