Skip to content

Column with ON UPDATE clause fails to compile #1391

Closed

Description

@kyleconroy

Version

1.11.0

What happened?

When creating a table with ON UPDATE, sqlc fails to generate code.

Originally reported by @danthegoodman1 in #1389

Relevant log output

sqlc generate failed.

# package db
query.sql:1:1: syntax error at or near "ON"

Database schema

CREATE TABLE authors (
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ON UPDATE NOW()
);

SQL queries

-- name: GetAuthor :one
SELECT * FROM authors;

Configuration

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

Playground URL

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

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Activity

  1. kyleconroy commented on Jan 24, 2022

    @kyleconroy
    CollaboratorAuthor

    ON UPDATE is not supported by PostgreSQL. I believe this is a CoackroachDB specific feature.

    $ psql
    psql (14.1)
    Type "help" for help.
    
    kyle=# CREATE TABLE authors (
    kyle(#   updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ON UPDATE NOW()
    kyle(# );
    ERROR:  syntax error at or near "ON"
    LINE 2:   updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ON UPDATE NO...
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions