Skip to content

Commit

Permalink
SQL - improve CAST('field' AS CHAR(n))
Browse files Browse the repository at this point in the history
SQL - improve CAST('field' AS CHAR(n))
  • Loading branch information
alikon committed Oct 15, 2016
1 parent 57e81ec commit 05b7858
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libraries/joomla/database/query/postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,26 @@ public function clear($clause = null)
*
* Usage:
* $query->select($query->castAsChar('a'));
* $query->select($query->castAsChar('a', 40));
*
* @param string $value The value to cast as a char.
*
* @param string $len The lenght of the char.
*
* @return string Returns the cast value.
*
* @since 11.3
*/
public function castAsChar($value)
public function castAsChar($value, $len = null)
{
return $value . '::text';
if (!$len)
{
return $value . '::text';
}
else
{
return ' CAST(' . $value . ' AS CHAR(' . $len . '))';
}
}

/**
Expand Down

0 comments on commit 05b7858

Please sign in to comment.