Re: Upsert error "column reference is ambiguous"

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Tim Starling <tstarling(at)wikimedia(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Upsert error "column reference is ambiguous"
Date: 2025-04-29 06:36:14
Message-ID: 10ff0fbe7f4d711300951431ad28254aa5bf2dc4.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2025-04-29 at 08:36 +1000, Tim Starling wrote:
> My code would be like
>
> function upsert( $table, $names, $values, $key, $set ) {
>      if ( $this->type === 'mysql' ) {
>          $conflict = 'ON DUPLICATE KEY UPDATE';
>      } else {
>          $conflict = "ON CONFLICT ($key) DO UPDATE SET";
>      }
>      return $this->query( "INSERT INTO $table ($names) " .
>          "VALUES ($values) $conflict $set" );
> }
>
> The parameters are a little bit more structured than that, but that
> gives you the idea.

Another litle "if" to cater for PostgreSQL's "EXCLUDED." would be
such a big problem?

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vydehi Ganti 2025-04-29 08:05:59 Re: Clarification on RLS policy
Previous Message Christophe Pettus 2025-04-28 23:01:23 Re: Upsert error "column reference is ambiguous"