Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Zend\Db\Sql\Replace? #6

Open
Koopzington opened this issue Jun 11, 2015 · 4 comments
Open

Zend\Db\Sql\Replace? #6

Koopzington opened this issue Jun 11, 2015 · 4 comments

Comments

@Koopzington
Copy link
Contributor

Zend\Db\Sql is missing a way to create a REPLACE INTO table_name VALUES(row_data) statement.
Thought, I'd add this here 'cause apparently noone else was missing that feature.

@weierophinney
Copy link
Member

We've purposely not implemented the feature in the past, as it's not part of any ANSI SQL standards, which means it would require emulation on many platforms. However, it appears that in recent years, most platforms implement it (see http://troels.arvin.dk/db/rdbms/#functions-REPLACE), and do so in essentially the same way. (SQLite even implements it, though that comparison does not include SQLite.)

As such, we can potentially add it as a feature at this time.

@mattfletcher
Copy link

@weierophinney the link you have given refers to the REPLACE string function, rather than REPLACE INTO syntax referred to by @Koopzington

REPLACE INTO allows one to ask if a matching record exists, and then either INSERT or UPDATE a record depending on the answer, in a single statement.

@froschdesign
Copy link
Member

@mattfletcher

the link you have given refers to the REPLACE string function, rather than REPLACE INTO syntax

Right!

REPLACE INTO allows one to ask if a matching record exists, and then either INSERT or UPDATE a record depending on the answer, in a single statement.

The same applies here:

We've purposely not implemented the feature in the past, as it's not part of any ANSI SQL standards, which means it would require emulation on many platforms.

The problem: every DBMS uses an own implementation outside from any standard. For example:

  • PostgreSQL: INSERT INTO ... ON CONFLICT (aka "UPSERT")
  • Mssql: WHEN NOT MATCHED BY SOURCE
  • MySQL: INSERT ... ON DUPLICATE KEY UPDATE
  • SQLite: INSERT OR REPLACE INTO

So the labels for this issue are correct: "help wanted"

@michalbundyra
Copy link
Member

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#147.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants