Wednesday, July 22, 2009

postgresql delete+join

almost always I think delete+join can be resolved with delete+exists

here's the source:

Re: DELETE with JOIN syntax

* From: Stephan Szabo
* To: Brian Wong
* Cc: pgsql-general(at)postgresql(dot)org
* Subject: Re: DELETE with JOIN syntax
* Date: Wed, 27 Jul 2005 13:14:13 -0700 (PDT)
* Message-id: <20050727130718.V16572@megazone.bigpanda.com>

On Wed, 27 Jul 2005, Brian Wong wrote:

> I am currently migrating from MySQL to PostgreSQL and I have found
> that some queries do not work. For instance,
>
> DELETE t1 FROM t1 LEFT JOIN t2 USING (column_id) WHERE t2.column_id IS NULL;
>
> works in MySQL. This works as expected even though the MySQL
> documentation does not mention the option of having a table between
> the keywords DELETE and FROM.
>
> I am trying to achieve the same affect for PostgreSQL so I tried
>
> DELETE FROM t1 LEFT JOIN t2 USING (column_id) WHERE t2.column_id IS NULL;
>
> and it did not work. Can someone explain to me exactly what is wrong
> with this syntax?

It's mostly that AFAIK SQL has no equivalent syntax.

> Is a table expression produced by the JOIN allowed for a DELETE?
> Im thinking that this would not work because the table expression is
> not a real table and it would not make sense for DELETE to accept such
> a parameter. How can I rewrite this query to achieve the same affect?

I think the where t2.column_id is null where column_id is the joining
column makes this a form of not exists, so maybe:

DELETE FROM t1 WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE t2.column_id =
t1.columnid);

Tuesday, July 7, 2009

Clave de root para mysql

tomado de: http://el-directorio.org/ErroresComunesPhpmyadmin

ARREGLAR ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

* Mi version de mysql es:

mysql Ver 14.12 Distrib 5.0.45

* Este error me salio una vez entre por PHPMyadmin y por error borre el acceso de root en esta parte:

1.png

* Entonces una vez intentaba entrar me salia el siguiente error:

sergiokof:/home/sergiokof# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

* Teniendo en cuenta que no le habia colocado ningun password a mysql, y si intentaba entrar por localhost/phpmyadmin/index.php me aparecia lo mismo:

2.png

* La solucion fue la siguiente:

1. Paramos los servicios de mysql:

/etc/init.d/mysql stop

2. con el siguiente comando nos saltamos los privilegios de mysql

/usr/bin/mysqld_safe --user=mysql --skip-grant-tables

3.Abirmos otra consola y escribimos lo siguiente:

sergiokof:/home/sergiokof# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.45-Debian_1-log Debian etch distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

4.Ahora que si pudimos ingresar digitamos:

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>

5.Ahora le colocamos una clave a mysql

mysql> UPDATE user SET Password=PASSWORD('password') WHERE user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

6.Volvemos a iniciar mysql y todo queda perfecto :

sergiokof:/home/sergiokof# mysql -u root -p
Enter password:*************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.45-Debian_1-log Debian etch distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Solución 2 Problema (1045) en phpmyadmin

bueno yo hice una solución muy rara pero funciono y volvi acceder a mi phpmyadmin ya que no podia acceder y me aparecia el error 1045,esto fue por que por que borre los usuarios.

1. entre a /var/www/ruta phpmyadmin por defecto utilizan mucho /var/www/phpmyadmin pero la entrada no la haga atraves de un navegador, utilize el navegador de ventanas en este caso utilice nautilus o una consola.

2.encontrara un archivo llamado config.inc.sample.php abralo y renombrelo como config.inc.php dentro de la misma carpeta y guardelo/var/www/ruta del phpmyadmin.

3. cambiele algunos parametros como

$cfg["blowfish.secret"]=" Aqui colocas una palabra secreta"

$cfg["servers"][$i]["controluser"]=" Aqui colocas el usuario para phpmyadmin"

En esta linea yo volvi a utilizar root , pero puedes utilizar y recrear un nuevo usuario.

$cfg["servers"][$i]["controlpass"]=" Aqui colocas la clave para ese usuario"

Guarde y listo ..¡¡¡¡

*

ya puedes acceder en tu navegador a http://localhost/phpmyadmin y accede con el usuario que colocaste en config.inc.php

Espero que les pueda servir para que no se maten la cabeza ;-)

[sergiokof] [KaL]

#2002 - El servidor no está respondiendo (o el socket del servidor MySQL local no está configurado correctamente

Bueno primero que todo hay que mirar si mysql-server esta instalado completamente, estos lo podemos saber si esta instruccion hace reiniciar o iniciar el socket de mysql.

sudo /etc/init.d/mysql restart

de lo contrario intentemos instalar

apt-get install mysql-server

ahora solo entraremos a la ruta de http://localhost/phpmyadmin y entraremos con el usuario ROOT sin contraseña y listo.

CategoryAyuda

ErroresComunesPhpmyadmin (last edited 2008-07-23 16:07:54 by KaL23)

* Immutable Page

DeleteCache (cached 2009-04-18 19:32:59)

Or try one of these actions: Attachments, CopyPage, Despam, LikePages, Literate, Load, LocalSiteMap, MyPages, PackagePages, PermanentLink, RenderAsDocbook, Save, SpellCheck, SubscribeUser, SyncPages

* MoinMoin Powered
* Python Powered
* GPL licensed
* Valid HTML 4.01

cancel script completely on ctrl-c

I found this question interesting: basically how to cancel completely a script and all child processes : You do this by creating a subro...