DefaultTo postgres functions
See original GitHub issueIs there a way to set a defaultTo
to a column a postgresql function? For example If I want to have an uuid column auto generate using uuid_generate_v4()
.
I’m currently running this as a separate migration setting the default using raw sql. Is there any way to do it as part of the migration itself?
For example
t.uuid('transact_id').defaultTo(default.uuid_generate_v4());
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Documentation: 15: 5.2. Default Values
In a table definition, default values are listed after the column data type. For example: CREATE TABLE products ( product_no integer, name text,...
Read more >values in function, arguments dependency, PostgreSQL
CREATE OR REPLACE FUNCTION years_compare( IN year1 integer DEFAULT NULL, IN year2 integer DEFAULT NULL ) year1 = COALESCE(year1, ...
Read more >Default value for column postgres function with argument
Unfortunately, you cannot do that, because of (for the documentation):. The value is any variable-free expression (subqueries and ...
Read more >How to set a column default to a PostgreSQL function using ...
Postgresql – How to set a column default to a PostgreSQL function using SQLAlchethe. postgresqlsqlalchemyuuid. All of my tables defined in SQLAlchemy have ......
Read more >PostgreSQL Functions
Most PostgreSQL functions accept connection as the optional first parameter. ... Apache (perhaps other servers, too) running the server as (default to) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Have you tried:
Note to add, for Postgres 9 and greater, you will need to run this SQL on the database to enable using uuid_generate_v4() functions:
This resolves an issue where running a migration on a PostgreSQL DB errors on a message like “function uuid_generate_v4() does not exist”.