DBLINK_B...QL_DELETE(3)

πŸ“¦ version 18.6, in opensuse-leap 16.0

okay bestie, so this is dblink_build_sql_delete from the DBLINK_B...QL_DELETE(3) manual, shipped with PostgreSQL 18.6 Documentation. it's giving "utility function that does exactly one thing and does it well." periodt.


✨ NAME ✨

dblink_build_sql_delete β€” builds a DELETE statement using supplied values for primary key field values

like. that's the whole job. it takes ur primary key values and hands u back a ready-to-go DELETE. no cap.


πŸŽ€ SYNOPSIS πŸŽ€

dblink_build_sql_delete(text relname,
                        int2vector primary_key_attnums,
                        integer num_primary_key_atts,
                        text[] tgt_pk_att_vals_array) returns text

πŸ¦‹ DESCRIPTION πŸ¦‹

so dblink_build_sql_delete can be useful in doing selective replication of a local table to a remote database. it builds an SQL DELETE command that will delete the row with the given primary key values. that's it, that's the vibe. u give it the goods, it gives u back the statement. πŸ’…


🌸 ARGUMENTS 🌸

  • relname β€” name of a local relation, for example foo or myschema.mytab. include double quotes if the name is mixed-case or contains special characters, for example "FooBar"; without quotes, the string will be folded to lower case. (yes, lowercase folding is real and yes it will humble u. 🫠)
  • primary_key_attnums β€” attribute numbers (1-based) of the primary key fields, for example 1 2.
  • num_primary_key_atts β€” the number of primary key fields.
  • tgt_pk_att_vals_array β€” values of the primary key fields to be used in the resulting DELETE command. each field is represented in text form.

πŸ’œ RETURN VALUE πŸ’œ

returns the requested SQL statement as text. iconic behaviour, honestly. no mystery, no surprises, just a string. ⭐


πŸ‘‘ NOTES πŸ‘‘

as of PostgreSQL 9.0, the attribute numbers in primary_key_attnums are interpreted as logical column numbers, corresponding to the column's position in SELECT * FROM relname. previous versions interpreted the numbers as physical column positions. there is a difference if any column(s) to the left of the indicated column have been dropped during the lifetime of the table. πŸ’€

so like... if ur table has been through some things (dropped columns 😭), the number u pass means something different than it used to. log that in ur brain, bestie. this is the iykyk part of the page.


🌈 EXAMPLES 🌈

SELECT dblink_build_sql_delete('"MyFoo"', '1 2', 2, '{"1", "b"}');
           dblink_build_sql_delete
---------------------------------------------
 DELETE FROM "MyFoo" WHERE f1='1' AND f2='b'
(1 row)

look at her go. one call, one clean DELETE, one row back. ate. πŸ”₯


πŸ“ SEE ALSO πŸ“

(no SEE ALSO section on this page β€” so instead: go read the rest of the dblink family, they're all serving their own little purposes 🧚)


and that's the page!! written by the PostgreSQL 18.6 Documentation crew, dated 2026, manual section DBLINK_B...QL_DELETE(3). mwah πŸ’– go build some DELETE statements responsibly, bestie. πŸŽ€
πŸ“¦ where this page comes from