Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 4932 postgresql default constraint functions #4934

Conversation

griffio
Copy link
Contributor

@griffio griffio commented Dec 22, 2023

fixes #4932 - compiler error when functions are used as DEFAULT column values

😑 Currently the work-around/escape-hatch is to enclose the function in parentheses as this matches the grammar ruleLP expr RP

Add {function_expr} to the default_constraint rule

Other consideration is that ideally the function result type must be assignable to the column type 🔡 🔢 and would need to be compiler checked - currently none of the DEFAULT types are checked and can be any type of expression 🤭

CREATE TABLE t1(
  c1 UUID DEFAULT gen_random_uuid(),
  c2 INTEGER DEFAULT nextval('some_seq')
);

💡 Ideally - SqlDelight would provide error

CREATE TABLE t1(
  c1 INTEGER DEFAULT gen_random_uuid()
);

Postgresql does provide error
error: column "c1" is of type integer but default expression is of type uuid

e.g

CREATE TABLE t1 (

  c1 UUID DEFAULT gen_random_uuid(),

  c2 INTEGER DEFAULT nextval('some_seq')

);
@griffio griffio force-pushed the fixes-4932-postgresql-default-constraint_functions branch from f5f73e0 to ad86966 Compare January 3, 2024 17:56
@griffio griffio marked this pull request as ready for review January 3, 2024 18:49
@AlecKazakova AlecKazakova merged commit 3d59a81 into cashapp:master Jan 29, 2024
7 checks passed
@griffio griffio deleted the fixes-4932-postgresql-default-constraint_functions branch January 29, 2024 15:38
hfhbd pushed a commit that referenced this pull request Apr 2, 2024
* Support functions in default column definition

e.g

CREATE TABLE t1 (

  c1 UUID DEFAULT gen_random_uuid(),

  c2 INTEGER DEFAULT nextval('some_seq')

);

* Add simple fixture test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error generating Postgres dialect with gen_random_uuid()
2 participants