# Copy and paste recipe saved in database via script

**URL:** <https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262>\
**Category:** Ignition\
**Tags:** vision, ignition81, database\
**Created:** [October 10, 2023, 9:25am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262 "2023-10-10T09:25:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [October 10, 2023, 9:25am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/1 "2023-10-10T09:25:43Z")

</div>

Good morning,  
I'm trying to look for the best solution for this problem.

I have a table in a sql server database and I would like create a button "Save as" where I select a already created recipe name and I choose a new name to save so to have a copy of an oldrecord with a different name.

I guess I could do something like this, but I wonder how I can change the recipe name

```auto
insert into recipes
select*from recipes
where RecipeName = selectedRecipeName

```

Should I make an update after this?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 10, 2023, 9:56am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/2 "2023-10-10T09:56:44Z")

</div>

It might help to tag your question as Vision or Perspective.

Your title doesn't match the question. This is not a "copy and paste" question.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 10, 2023, 9:57am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/3 "2023-10-10T09:57:19Z")

</div>

```sql
insert into recipes
select 'new_name', foo, bar, pox, wuz
from recipes
where RecipeName = selectedRecipeName

```

> [@Transistor](#):
>
> It might help to tag your question as Vision or Perspective.

I don't think perspective/vision is relevant here, but it should probably be tagged 'database' or whatever is the closest in the tags list

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 10, 2023, 9:59am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/4 "2023-10-10T09:59:20Z")

</div>

Pascal, does the insert work when you haven't specified the field names?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 10, 2023, 10:00am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/5 "2023-10-10T10:00:43Z")

</div>

Yep, at least with mssql. If you're inserting "everything", you don't need to specify what you're inserting.  
Won't work with a `select *` though as you'd also be pulling the id.  
Gotta be careful with the order though. It may be better to make the columns explicit...

```plaintext
insert into recipes (RecipeName, foo, bar, pox, wuz)
select 'new_name', foo, bar, pox, wuz
from recipes
where RecipeName = selectedRecipeName

```

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [October 10, 2023, 11:09am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/6 "2023-10-10T11:09:46Z")

</div>

@Transistor, I'm sorry for the title, the copy and paste is my goal, but if is better to change it to be more clear please tell me how to change. I change the tag as you suggest.

@pascal.fragnoud, I would prefer to make a `Select *` because I have hundred of columns and happen that I need to add new ones, so I should insert them manually.

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [October 10, 2023, 11:50am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/7 "2023-10-10T11:50:08Z")

</div>

I'm testing it with this script with no success

```auto

RecipeName = system.tag.readBlocking("path")[0].value

query = """
			INSERT INTO Recipe_A4 
			SELECT * 
			FROM Recipe_A4 
			WHERE RecipeName = ?
			"""
					
args = ["%s" % RecipeName]

ds = system.db.runPrepUpdate(query, args)	

```

but I have this error (I translate it because the error in not in english), I hope the translation is correct

_ **You can specify an explicit value for the identity column in the table 'Recipe\_A4 ' only when using a list of columns and IDENTITY\_INSERT has a value of ON** _

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 10, 2023, 12:03pm UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/8 "2023-10-10T12:03:51Z")

</div>

It means you're trying to manually set the value of an automatic column. You can't do that, and that's why you can't use `select *`.

If you don't want to manually type everything, I guess you could do a `select *` from your table in the script console, print the column names, copy and paste them, and remove the id column...

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [October 11, 2023, 7:44am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/9 "2023-10-11T07:44:38Z")

</div>

Thank you for the help. At this point I will do as you suggest.

I exctract the column names in the script console with this

```auto
ds = system.db.runPrepQuery(query, args)	
rsDataset = system.dataset.toPyDataSet(ds) 

print rsDataset.getColumnNames()

```

and I have the results in one single row like this

```auto
[ricette_a4_ndx, Col1, Col2, ecc]

```

How could I have the results row by row like this

```auto
ricette_a4_ndx, 
Col1, 
Col2, 
ecc

```

just to be faster with the copy of the names

Thank you

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 11, 2023, 7:48am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/10 "2023-10-11T07:48:08Z")

</div>

```python
print '\n'.join(column_names)

```

or

```python
for col in column_names:
    print col

```

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [October 11, 2023, 8:55am UTC](https://forum.inductiveautomation.com/t/copy-and-paste-recipe-saved-in-database-via-script/80262/11 "2023-10-11T08:55:18Z")

</div>

Thank you very much, have a nice day.
