Skip to content

sqlc not working with datatype UUID #2720

Closed as not planned
Closed as not planned
@mbe81

Description

@mbe81

Version

1.21.0

What happened?

Since MariaDB 10.7 there is a native UUID data type. Using this data type in the schema definition gives an error when generating code:

sqlc generate failed.
# package db
query.sql:2:9: syntax error near "uuid primary key,"

Workaround

When I change the datatype in the schema.sql from uuid to binary and add an override in the sqlc.yaml the generation works as expected.

updated schema.sql:

create table user (
	id binary default uuid() not null primary key,
	name varchar(50) not null,
	email varchar(255) not null,
	password_hash varchar(60) not null,
	created_datetime timestamp not null default current_timestamp(),
	updated_datetime timestamp not null default current_timestamp() on update current_timestamp()
);

updated sqlc.yaml:

overrides:
  go:
    overrides:
      - db_type: "binary"
        nullable: false
        engine: "mysql"
        go_type:
          import: "github.com/google/uuid"
          type: "UUID"

However, changing the data type in the schema.sql is not desired because it does not reflect reality.


Database schema

create table user (
	id uuid default uuid() not null primary key,
	name varchar(50) not null,
	email varchar(255) not null,
	password_hash varchar(60) not null,
	created_datetime timestamp not null default current_timestamp(),
	updated_datetime timestamp not null default current_timestamp() on update current_timestamp()
);

SQL queries

-- name: listUsers :many
select * from user;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "mysql",
      "schema": "schema.sql",
      "queries": "queries.sql"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/e7301e06df354e56281efe68b535030621c6432705b11e54f542b1e322241858

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Labels

    📚 mariadbbugSomething isn't workingupstreamIssue is caused by a dependency

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions