public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
	{
		// To check if table exists and prevent SQL injection
		$tableList = $this->getTableList();

		// Origin Table does not exist
		if (!in_array($oldTable, $tableList, true))
		{
			throw new \RuntimeException('Table not found in Postgres database.');
		}

		// Rename indexes
		$subQuery = $this->getQuery()
			->select('indexrelid')
			->from('pg_index')
			->join('pg_class', 'pg_class.oid', 'pg_index.indrelid')
			->whereEquals('pg_class.relname', $oldTable)
			->toString();

		$this->setQuery(
			$this->getQuery()
				->select('relname')
				->from('pg_class')
				->whereRaw('oid IN (' . (string) $subQuery . ')')
				->toString()
		);

		$oldIndexes = $this->loadColumn();

		foreach ($oldIndexes as $oldIndex)
		{
			$changedIdxName = str_replace($oldTable, $newTable, $oldIndex);
			$this->setQuery('ALTER INDEX ' . $this->escape($oldIndex) . ' RENAME TO ' . $this->escape($changedIdxName))->execute();
		}

		// Rename sequences
		$subQuery = $this->getQuery()
			->select('oid')
			->from('pg_namespace')
			->whereNotLike('nspname', 'pg_%')
			->where('nspname', '!=', 'information_schema')
			->toString();

		$this->setQuery(
			$this->getQuery()
				->select('relname')
				->from('pg_class')
				->whereEquals('relkind', 'S')
				->whereRaw('relnamespace IN (' . (string) $subQuery . ')')
				->whereLike('relname', "%$oldTable%")
				->toString()
		);

		$oldSequences = $this->loadColumn();

		foreach ($oldSequences as $oldSequence)
		{
			$changedSequenceName = str_replace($oldTable, $newTable, $oldSequence);
			$this->setQuery('ALTER SEQUENCE ' . $this->escape($oldSequence) . ' RENAME TO ' . $this->escape($changedSequenceName))->execute();
		}

		// Rename table
		$this->setQuery('ALTER TABLE ' . $this->escape($oldTable) . ' RENAME TO ' . $this->escape($newTable))->execute();

		return true;
	}
public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
	{
		// To check if table exists and prevent SQL injection
		$tableList = $this->getTableList();

		// Origin Table does not exist
		if (!in_array($oldTable, $tableList, true))
		{
			throw new \RuntimeException('Table not found in Postgres database.');
		}

		// Rename indexes
		$subQuery = $this->getQuery()
			->select('indexrelid')
			->from('pg_index')
			->join('pg_class', 'pg_class.oid', 'pg_index.indrelid')
			->whereEquals('pg_class.relname', $oldTable)
			->toString();

		$this->setQuery(
			$this->getQuery()
				->select('relname')
				->from('pg_class')
				->whereRaw('oid IN (' . (string) $subQuery . ')')
				->toString()
		);

		$oldIndexes = $this->loadColumn();

		foreach ($oldIndexes as $oldIndex)
		{
			$changedIdxName = str_replace($oldTable, $newTable, $oldIndex);
			$this->setQuery('ALTER INDEX ' . $this->escape($oldIndex) . ' RENAME TO ' . $this->escape($changedIdxName))->execute();
		}

		// Rename sequences
		$subQuery = $this->getQuery()
			->select('oid')
			->from('pg_namespace')
			->whereNotLike('nspname', 'pg_%')
			->where('nspname', '!=', 'information_schema')
			->toString();

		$this->setQuery(
			$this->getQuery()
				->select('relname')
				->from('pg_class')
				->whereEquals('relkind', 'S')
				->whereRaw('relnamespace IN (' . (string) $subQuery . ')')
				->whereLike('relname', "%$oldTable%")
				->toString()
		);

		$oldSequences = $this->loadColumn();

		foreach ($oldSequences as $oldSequence)
		{
			$changedSequenceName = str_replace($oldTable, $newTable, $oldSequence);
			$this->setQuery('ALTER SEQUENCE ' . $this->escape($oldSequence) . ' RENAME TO ' . $this->escape($changedSequenceName))->execute();
		}

		// Rename table
		$this->setQuery('ALTER TABLE ' . $this->escape($oldTable) . ' RENAME TO ' . $this->escape($newTable))->execute();

		return true;
	}
public function renameTable ( $ oldTable , $ newTable , $ backup = null , $ prefix = null ) { // To check if table exists and prevent SQL injection $ tableList = $ this -> getTableList ( ) ; // Origin Table does not exist if ( ! in_array ( $ oldTable , $ tableList , true ) ) { throw new \ RuntimeException ( 'Table not found in Postgres database.' ) ; } // Rename indexes $ subQuery = $ this -> getQuery ( ) -> select ( 'indexrelid' ) -> from ( 'pg_index' ) -> join ( 'pg_class' , 'pg_class.oid' , 'pg_index.indrelid' ) -> whereEquals ( 'pg_class.relname' , $ oldTable ) -> toString ( ) ; $ this -> setQuery ( $ this -> getQuery ( ) -> select ( 'relname' ) -> from ( 'pg_class' ) -> whereRaw ( 'oid IN (' . ( string ) $ subQuery . ')' ) -> toString ( ) ) ; $ oldIndexes = $ this -> loadColumn ( ) ; foreach ( $ oldIndexes as $ oldIndex ) { $ changedIdxName = str_replace ( $ oldTable , $ newTable , $ oldIndex ) ; $ this -> setQuery ( 'ALTER INDEX ' . $ this -> escape ( $ oldIndex ) . ' RENAME TO ' . $ this -> escape ( $ changedIdxName ) ) -> execute ( ) ; } // Rename sequences $ subQuery = $ this -> getQuery ( ) -> select ( 'oid' ) -> from ( 'pg_namespace' ) -> whereNotLike ( 'nspname' , 'pg_%' ) -> where ( 'nspname' , '!=' , 'information_schema' ) -> toString ( ) ; $ this -> setQuery ( $ this -> getQuery ( ) -> select ( 'relname' ) -> from ( 'pg_class' ) -> whereEquals ( 'relkind' , 'S' ) -> whereRaw ( 'relnamespace IN (' . ( string ) $ subQuery . ')' ) -> whereLike ( 'relname' , "%$oldTable%" ) -> toString ( ) ) ; $ oldSequences = $ this -> loadColumn ( ) ; foreach ( $ oldSequences as $ oldSequence ) { $ changedSequenceName = str_replace ( $ oldTable , $ newTable , $ oldSequence ) ; $ this -> setQuery ( 'ALTER SEQUENCE ' . $ this -> escape ( $ oldSequence ) . ' RENAME TO ' . $ this -> escape ( $ changedSequenceName ) ) -> execute ( ) ; } // Rename table $ this -> setQuery ( 'ALTER TABLE ' . $ this -> escape ( $ oldTable ) . ' RENAME TO ' . $ this -> escape ( $ newTable ) ) -> execute ( ) ; return true ; }
Renames a table in the database

@param   string  $oldTable  The name of the table to be renamed
@param   string  $newTable  The new name for the table
@param   string  $backup    Table prefix
@param   string  $prefix    For the table - used to rename constraints in non-mysql databases
@return  $this
@since   2.2.15
Renames a table in the database