Skip to main content
Solved

How to insert into a Link field when accessing Airtable via SQL

  • October 26, 2023
  • 3 replies
  • 51 views

Forum|alt.badge.img+4

Im using Retool with Sequin to link my airtable database to Retool and im trying to insert into a link field some data but i cant do it like how i would normally insert a field with a sql query

Best answer by Alexey_Gusev

You can't just put some random text to link field.
Usual value of link field is array of objects:

When you work with usual Airtable in browser or app, you can paste value or values, separated by comma.
each value is a Name of record to link.
These values should exist in the primary field of a linked table, otherwise it creates a new record with such name (name is a value of a primary field) and empty other fields. If record can't be created, it does nothing.

In script, you usually need to put array of IDs, not a list of strings. Like this.
[ {'id':'rec123Abc456dEF'} , {'id':'rec890qwerTYUI'} ]

to clean cell, you need to pass empty array  [] 

3 replies

Alexey_Gusev
Forum|alt.badge.img+25
  • Brainy
  • Answer
  • October 28, 2023

You can't just put some random text to link field.
Usual value of link field is array of objects:

When you work with usual Airtable in browser or app, you can paste value or values, separated by comma.
each value is a Name of record to link.
These values should exist in the primary field of a linked table, otherwise it creates a new record with such name (name is a value of a primary field) and empty other fields. If record can't be created, it does nothing.

In script, you usually need to put array of IDs, not a list of strings. Like this.
[ {'id':'rec123Abc456dEF'} , {'id':'rec890qwerTYUI'} ]

to clean cell, you need to pass empty array  [] 


Forum|alt.badge.img+4
  • Author
  • New Participant
  • October 30, 2023

i ended up with the next insert query: 

INSERT INTO table (linkfield) VALUES ('recipxpYRlJ16okEX')

and it worked, thank you very much.


Alexey_Gusev
Forum|alt.badge.img+25

i ended up with the next insert query: 

INSERT INTO table (linkfield) VALUES ('recipxpYRlJ16okEX')

and it worked, thank you very much.


Great to know. As former MSSQL DBA, I tried to find a way to use T-SQL in Airtable, didn't find an easy way to do it. Then I learned JS basics and found it more convenient for my purposes.