News for hackers. Stuff that matters.
Re:Let Postgres Do the Work (2013) by dllthomas on Saturday November 26, 2016 @03:59PM (#13045820)
> This allows for version control to track the changes of the sql function.

You... realize you could just put the SQL itself in git, right? Not saying there aren't potential benefits, but "it can go in version control" isn't one of them.

Re:Let Postgres Do the Work (2013) by phereford on Saturday November 26, 2016 @04:02PM (#13045838)
Absolutely! We use rails. I just mentioned doing it in that method as opposed to throwing it in a migration. That migration shouldn't change in version control. We wanted a history of the changes and an easy way to access it in migrations.

Sorry for not explaining that fully.

Re:Let Postgres Do the Work (2013) by rpeden on Saturday November 26, 2016 @04:58PM (#13046123)
Makes sense.

I suppose you could also execute "REPLACE FUNCTION" and redefine the inside a new migration each time you want to change it. The downside is that you end up with the whole function in new a migration every time you want to change if. But if you're not updating your stored procedures very frequently (which is usually the case, IME), it probably wouldn't be too bad.

Re:Let Postgres Do the Work (2013) by jeffasinger on Saturday November 26, 2016 @05:12PM (#13046200)
At work we use a rather idiosyncratic tool called RoundhousE to deploy our SQL. It treats sql labelled as a stored procedure differently, and will run the file on every deploy, as opposed to scripts that alter the schema, which are only ran once, and may not be modified.

The system works pretty well.

Re:Let Postgres Do the Work (2013) by slagfart on Saturday November 26, 2016 @05:31PM (#13046311)
You don't need a tool for this. If you store base data in one schema, and functions/views in another, you can update this second schema willy nilly without worrying about damaging your data.

Just start the second file with DROP SCHEMA IF EXISTS schemaname CASCADE; CREATE SCHEMA schemaname;. Then, make sure any functions/views/permissions built on top of this schema are also contained within this file.

Re:Let Postgres Do the Work (2013) by inopinatus on Saturday November 26, 2016 @06:21PM (#13046612)
Or you can just pull the SQL for the stored procedure from a table column and execute it dynamically.

Now it's an ops problem :-)

Re:Let Postgres Do the Work (2013) by jessaustin on Sunday November 27, 2016 @07:54AM (#13048903)
Haha, usually we hear this from smart guys who have been working for about 8 months...
Re:Let Postgres Do the Work (2013) by angersock on Saturday November 26, 2016 @10:45PM (#13047573)
Oh, that's slick. Nice!
Re:Let Postgres Do the Work (2013) by inopinatus on Saturday November 26, 2016 @06:09PM (#13046542)
Or you can just define the function every time you use it. https://www.postgresql.org/docs/current/static/sql-do.html
Re:Let Postgres Do the Work (2013) by majewsky on Saturday November 26, 2016 @06:26PM (#13046640)
That won't help if you want to use it for indexing, as the article demonstrated.
Re:Let Postgres Do the Work (2013) by pmontra on Sunday November 27, 2016 @02:55AM (#13048239)
You are right but a Rails migration would provide a way to deploy to the database. Far from ideal though, because you could have many migrations with that SQL code, one for each version of the code. Not sure what's the best solution in this case.